How to solve "system contains a nonlinear equation"

조회 수: 3 (최근 30일)
Fatemeh
Fatemeh 2023년 5월 7일
댓글: Fatemeh 2023년 5월 7일
Hello, when I run the code below, I get an error because the square of the second derivative of y(x) is used. Could someone please tell me how I can solve this type of problem?
syms y(x) x Y
mum=2;
r=0.05;
m=0.01;
p=1;
s=1;
t=0.1;
a=0.25;
b=0.25;
l=0.5;
t0= ((1/(r+p*s-m))^(1/(1-a-b)))+((1/(r+p*s-m))^(1/(1-a-b)))*((1/(r+t*p*s-m))^(1/(1-l)));
Dy = diff(y);
D2y = diff(y,2);
mo=1/(r-((p*Dy*x*s*mum)/y)-((Dy*x*mum)/y)+((Dy*x*mum*m)/y)-((Dy*x*(s^2)*(mum^2))/y)-((D2y*(x^2)*(s^2)*(mum^2))/(2*y)));
mi=1/(r-((t*p*Dy*x*s*mum)/y)-((Dy*x*mum)/y)+((Dy*x*mum*m)/y)-((Dy*x*(s^2)*(mum^2))/y)-((D2y*(x^2)*(s^2)*(mum^2))/(2*y)));
ode = y-(1/x)*(mo^(1/(1-a-b))+mo^(1/(1-a-b))* mi^(1/(1-l)));
[VF,Subs] = odeToVectorField(ode);
Error using mupadengine/feval_internal
System contains a nonlinear equation in 'diff(y(x), x, x)'. The system must be quasi-linear: highest derivatives must enter the differential equations linearly.

Error in odeToVectorField>mupadOdeToVectorField (line 171)
T = feval_internal(symengine,'symobj::odeToVectorField',sys,x,stringInput);

Error in odeToVectorField (line 119)
sol = mupadOdeToVectorField(varargin);
odefcn = matlabFunction(VF, 'Vars',{x,Y});
bcfcn = @(ya,yb)[ya(1)-t0;yb(1)];
xmesh = linspace(1,80,150);
solinit = bvpinit(xmesh, [0 0]);
sol = bvp4c(odefcn,bcfcn,solinit);
plot(sol.x,sol.y(1,:))

답변 (1개)

Walter Roberson
Walter Roberson 2023년 5월 7일
편집: Walter Roberson 2023년 5월 7일
syms y(x) x Y
mum=2;
r=0.05;
m=0.01;
p=1;
s=1;
t=0.1;
a=0.25;
b=0.25;
l=0.5;
t0= ((1/(r+p*s-m))^(1/(1-a-b)))+((1/(r+p*s-m))^(1/(1-a-b)))*((1/(r+t*p*s-m))^(1/(1-l)));
Dy = diff(y);
D2y = diff(y,2);
mo=1/(r-((p*Dy*x*s*mum)/y)-((Dy*x*mum)/y)+((Dy*x*mum*m)/y)-((Dy*x*(s^2)*(mum^2))/y)-((D2y*(x^2)*(s^2)*(mum^2))/(2*y)));
mi=1/(r-((t*p*Dy*x*s*mum)/y)-((Dy*x*mum)/y)+((Dy*x*mum*m)/y)-((Dy*x*(s^2)*(mum^2))/y)-((D2y*(x^2)*(s^2)*(mum^2))/(2*y)));
ode = y-(1/x)*(mo^(1/(1-a-b))+mo^(1/(1-a-b))* mi^(1/(1-l)));
ode
ode(x) = 
The denominator has d^2y/dx^2 in it, and that term is squared, so the square of d^2y/dx^2 appears in the equation.
sode = simplify(expand(ode(x)), 'steps', 50)
sode = 
If you look at which is d^2y/dx^2 you can see that it appears to the 4th power in the expanded version, so the situation might be even worse than it seems at first.
  댓글 수: 6
Torsten
Torsten 2023년 5월 7일
편집: Torsten 2023년 5월 7일
Then try it out:
syms y Dy D2y x Y
mum=2;
r=0.05;
m=0.01;
p=1;
s=1;
t=0.1;
a=0.25;
b=0.25;
l=0.5;
t0= ((1/(r+p*s-m))^(1/(1-a-b)))+((1/(r+p*s-m))^(1/(1-a-b)))*((1/(r+t*p*s-m))^(1/(1-l)));
mo=1/(r-((p*Dy*x*s*mum)/y)-((Dy*x*mum)/y)+((Dy*x*mum*m)/y)-((Dy*x*(s^2)*(mum^2))/y)-((D2y*(x^2)*(s^2)*(mum^2))/(2*y)));
mi=1/(r-((t*p*Dy*x*s*mum)/y)-((Dy*x*mum)/y)+((Dy*x*mum*m)/y)-((Dy*x*(s^2)*(mum^2))/y)-((D2y*(x^2)*(s^2)*(mum^2))/(2*y)));
ode = y-(1/x)*(mo^(1/(1-a-b))+ mi^(1/(1-l)))
ode = 
D2ynum = solve(ode==0,D2y);
D2ynum = D2ynum(2);
f = matlabFunction(D2ynum,"Vars",{x, [y Dy]});
odefcn = @(x,y)[y(2);f(x,[y(1),y(2)])];
bcfcn = @(ya,yb)[ya(1)-t0;yb(1)];
xmesh = linspace(1,80,150);
solinit = bvpinit(xmesh, [1 1]);
sol = bvp4c(odefcn,bcfcn,solinit);
plot(sol.x,sol.y)
Fatemeh
Fatemeh 2023년 5월 7일
Thanks much @Torsten

댓글을 달려면 로그인하십시오.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by