MATLAB: How do you use fsolve to solve simultaneous equations

fsolve

Hello,
I am new to Matlab and would like to learn how to use fsolve to solve simultaneous equations.
Say you have the following equations:
x+y+z=2
y^2=z+5
x+z^3=2
Zero degrees of freedom, how do you solve for x, y and z using fsolve?
Thank you very much,
M

Best Answer

You need to rewrite as F(X)=0 where X is your vector of unknowns
fun=@(X) [sum(X)-2; X(2)^2 -X(3)-5 ; X(1)+X(3)^3-2];
Then
x = fsolve(fun,x0)
where x0 is your initial guess. There are other input/output arguments that you can use to refine the behavior of FSOLVE (see "doc fsolve").