How do you solve simultaneous non-linear equations in Matlab? I figured out I need to use fsolve or lsqnonlin, but I couldn't get the right answer using fsolve.
The equations that I need to solve are in this form:
y1=1-2cos(x1)+2cos(x2)-2cos(x3)=0.5
y2=-2cos(3*x1)+2cos(3*x2)-2cos(3*x3)=0
y3=-2cos(5*x1)+2cos(5*x2)-2cos(5*x3)=0
I wrote the m-file like this
function z = abc(x)
z(1)=0.5-2*cos(x(1))+2*cos(x(2))-2*cos(x(3))
z(2)=-2*cos(3*x(1))+2*cos(3*x(2))-2*cos(3*x(3))
z(3)=-2*cos(5*x(1))+2*cos(5*x(2))-2*cos(5*x(3))
and solve it using something like this (might be a bit wronf since I don't have the code here with me)
x0=[10;20;30;40]
options=optimset('tolfun',1.0e-008);
[x,fval]=fsolve[@zbc,x0,options]
I found that by using different initai guess x0 I'll get different answer, and the solutions never converge and Matlab keeps asking me to try different x0. I have no idea what to choose, and the solutions I get never satisfy the given equations..
Can anyone help?
The equations that I need to solve are in this form:
y1=1-2cos(x1)+2cos(x2)-2cos(x3)=0.5
y2=-2cos(3*x1)+2cos(3*x2)-2cos(3*x3)=0
y3=-2cos(5*x1)+2cos(5*x2)-2cos(5*x3)=0
I wrote the m-file like this
function z = abc(x)
z(1)=0.5-2*cos(x(1))+2*cos(x(2))-2*cos(x(3))
z(2)=-2*cos(3*x(1))+2*cos(3*x(2))-2*cos(3*x(3))
z(3)=-2*cos(5*x(1))+2*cos(5*x(2))-2*cos(5*x(3))
and solve it using something like this (might be a bit wronf since I don't have the code here with me)
x0=[10;20;30;40]
options=optimset('tolfun',1.0e-008);
[x,fval]=fsolve[@zbc,x0,options]
I found that by using different initai guess x0 I'll get different answer, and the solutions never converge and Matlab keeps asking me to try different x0. I have no idea what to choose, and the solutions I get never satisfy the given equations..
Can anyone help?