Error using symengine Division by zero.

조회 수: 16 (최근 30일)
艺 李
艺 李 2022년 7월 1일
편집: KSSV 2022년 7월 1일
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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by