How do I get real roots only from the Newton Raphson method for solving multivariable equation?
1 次查看(过去 30 天)
显示 更早的评论
Hi All,
I'm using the following lines of codes to call on the new_raph.m function to get solutions for x & y.
b0=1;
z=linspace(0.5,1,2);
u0=(b0/2/pi).*asin(z);
x0=linspace(.1,.9,length(z)); y0=linspace(1*exp(1),5*exp(1),length(z));
syms x y
assume(x,'real')
assume(y,'real')
for j=1:length(z)
equation1=2.*x.*log(y)-(pi*y.^2.*z(j))+(y.^2.*asin(z(j)).*sin(2.*pi.*(u0(j)+x)/b0));
equation2=x.^2./y-2*pi.*y.*z(j).*x+2.*y.*(cos(2*pi.*u0(j)./b0)-cos(2.*pi.*(u0(j)+x)./b0));
[p(j) q(j)]=new_raph(equation1, equation2, x0(j),y0(j));
end
I only want real roots but the function is giving me complex roots. Can anyone suggest a better way of doing this where I can get real numbers only for the system of equations? Thanks!
1 个评论
Walter Roberson
2018-8-11
Never eval() a symbolic expression. Symbolic expressions are in a language which is not quite MATLAB.
Use \ in preference to inv() as inv() introduces inaccuracies.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!