How to rewrite a non-linear function so that f(x) = 0?
7 views (last 30 days)
Show older comments
Hello! This is my first question on these forums, so please forgive me if I do anything wrong here :). What I wonder about is how to make MATLAB rewrite a general, non-linear function. Say that I input the function "3cos(x) = x^2" or "e^x = 2x". Is there any function for this? What I want to do with this new, rewritten function is to use it to find the point of zero. This I plan to do with a function of my own, instead of using fzero. Thank you all in advance!
0 Comments
Accepted Answer
Walter Roberson
on 16 Dec 2011
You would have to input the equation as a string. Search for the '=' in the string, insert a '(' immediately after that and a ')' at the end, and convert the '=' to '-'. The result will be an expression with an implicit "= 0"
After that you have to figure out how to do calculations based upon a string. For that, please see http://www.mathworks.com/matlabcentral/answers/22330-can-you-have-the-user-input-an-equation-in-matlab
0 Comments
More Answers (4)
Honglei Chen
on 16 Dec 2011
Isn't it just
3*cos(x)-x^2
and
exp(x)-2*x
If you have to, you can define function f1(x) for the left side and f2(x) for the other side and then use f1(x)-f2(x). But IMHO it really doesn't save you anything.
0 Comments
Sean de Wolski
on 16 Dec 2011
If you have the Symbolic Math Toolbox, you can just use solve()
solve('exp(x)=2*x')
solve('3*cos(x)=x^2')
doc solve
Welcome to MATLAB Answers!
MORE
syms x
f1 = x^2-3
f2 = cos(x*exp(x))
simple(f2-f1)
0 Comments
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!