I have a set of nonlinear equations. And it was proved to have a unique solution. But I can't get the result by using matlab. I thought matlab is using Newton Method. Does anybody know what's wrong about this application?
I have a set of nonlinear equations. And it was proved to have a unique solution. But I can't get the result by using matlab. I thought matlab is using Newton Method. Does anybody know what's wrong about this application?
I also have a similar problem and I am having trouble writing a matlab program to solve it. My program so far is as follows:
I know it is far from complete but any advice or suggestions would be very much appreciated.Code:m=2.0; P=4.0; Q=5.0; f=@(x,y) y-((1/m)*((exp(x/m))+(exp(-x/m)))); g=@(x,y) ((x^2)/(P^2))+((y^2)/(Q^2))-1; fd1=@(x,y) (1/(m^2))*((exp(x/m))-(exp(-x/m))); fd2=@(x,y) 1; gd1=@(x,y) ((2*x)/(P^2)); gd2=@(x,y) ((2*y)/(Q^2)); i=1; N=100; TOL=0.001; x=1; y=1; while i<N A=[fd1 fd2; gd1 gd2];
You have the sign of df/dx wrong.
The following works:
CBCode:m=2.0; P=4.0; Q=5.0; f=@(x,y) y-(1/m)*(exp(x/m)+exp(-x/m)); g=@(x,y) (x^2)/(P^2)+(y^2)/(Q^2)-1; fd1=@(x,y) -(1/(m^2))*(exp(x/m)-exp(-x/m)); fd2=@(x,y) 1; gd1=@(x,y) (2*x)/(P^2); gd2=@(x,y) (2*y)/(Q^2); TOL=0.001; x=-1; y=-1; xx=zeros(2,1); err=100; while err>TOL J=[fd1(x,y) fd2(x,y); gd1(x,y) gd2(x,y)]; xx=[x;y]; xx=xx-inv(J)*[f(x,y);g(x,y)]; %xx=xx-J\[f(x,y);g(x,y)] would be better x1=xx(1);y1=xx(2); err=sqrt((x-x1)^2+(y-y1)^2); x=x1;y=y1; end xx