Error using symengine Division by zero.

16 views (last 30 days)
艺 李
艺 李 on 1 Jul 2022
Edited: KSSV on 1 Jul 2022
hello , here is Newton's method to solve the nonlinear equations, but when I solve the following equation system including 3 unknowns x1,x2,x3
equation 1:x1-pi/4*((2.5e+13-x2^2)*0.6^5/(0.0107*0.883*518.35*278*90000))^0.5- pi/4*((2.5e+13-x3^2)*0.6^5/(0.0107*0.883*518.35*278*80000))^0.5
equation 2:pi/4*((2.5e+13-x2^2)*0.6^5/(0.0107*0.883*518.35*278*90000))^0.5- pi/4*((x2^2-x3^2)*0.6^5/(0.0107*0.883*518.35*278*100000))^0.5-14.1031
equation 3:pi/4*((2.5e+13-x3^2)*0.6^5/(0.0107*0.883*518.35*278*80000))^0.5+ pi/4*((x2^2-x3^2)*0.6^5/(0.0107*0.883*518.35*278*100000))^0.5-28.2063
then it cannot proceed, and prompt
error using symengine
Division by zero.
error sym/subs>mupadsubs
G = mupadmex('symobj::fullsubs',F.s,X2,Y2);
error sym/subs
G = mupadsubs(F,X,Y);
However, when I change the equation, it CAN work well on other equations.Please tell me the reason, thanks a lot!!
the code are:
function [X] = Newton_Z(X,tol,N)
n = input('input the number of unknowns');
syms x [1 n]
ff=cell(n,1);
F=zeros(n,1);
Jx=cell(n,n);
J=zeros(n,n);
for i=1:n
f=input('enter the equation:');
ff{i,1}=f;
for j=1:n
Jx{i,j}=diff(f,x(j));
end
end
Jx
for k=1:N
X_old = X;
for i=1:n
ff_cpoy=ff{i,1};
for u=1:n
if u~=n
ff_cpoy=subs(ff_cpoy,x(u),X(u,1));
else
F(i,1)=vpa(subs(ff_cpoy,x(u),X(u,1)));
end
end
for j=1:n
Jx_copy=Jx{i,j};
for v=1:n
if v~=n
Jx_copy=subs(Jx_copy,x(v),X(v,1));
else
J(i,j)=vpa(subs(Jx_copy,x(v),X(v,1)));
end
end
end
end
X = X-J\F;
fprintf('iteration=%d ',k)
for i=1:n
value=X(i,1);
fprintf('x%d=%.8f ',i,value)
end
fprintf('\t')
fprintf('error:%.10f\n',norm(X_old-X, inf))
if norm(X_old-X, inf)<tol
break
end
if k==N
disp('reaches the max iteration times')
end
end

Answers (0)

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!