Error using mupadengine/feval_internal
11 次查看(过去 30 天)
显示 更早的评论
I'm trying to run this simple code in Matlab but I'm getting this error:
" 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);
Error in Untitled (line 11)
[VF,Subs] = odeToVectorField(ode);"
Could anyone please help me with this problem? I'm new to Matlab.
My code is :
syms y(x) x Y
r=0.05;
m=0.01;
p=1;
s=1;
a=0.25;
b=0.25;
Dy = diff(y);
D2y = diff(y,2);
ode= y-1/x*1/(r-((p*Dy*x*(s^2))/y)+((D2y*x*(s^2))/(2*y))+((Dy*(m-(s^2)))/y))^(1/(1-a-b));
[VF,Subs] = odeToVectorField(ode);
odefcn = matlabFunction(VF, 'Vars',{x,Y});
tspan = [20 80];
ic = [1 0];
[x,y] = ode45(odefcn, tspan, ic);
figure
plot(x, y)
grid
legend(string(Subs), 'loc','best')
0 个评论
采纳的回答
Walter Roberson
2023-4-11
syms y(x) x Y
r=0.05;
m=0.01;
p=1;
s=1;
a=0.25;
b=0.25;
Dy = diff(y);
D2y = diff(y,2);
ode= y-1/x*1/(r-((p*Dy*x*(s^2))/y)+((D2y*x*(s^2))/(2*y))+((Dy*(m-(s^2)))/y))^(1/(1-a-b))
Notice that the denominator has the second derivative of y(x), and notice that the entire term is squared -- so the square of the second derivative of y(x) is used in the ODE.
The error is saying that whatever the highest degree of derivative is used, that derivative must be used linearly -- it can be multiplied by constants but it cannot be raised to any power (other than 0, which would remove the term, or 1, which would leave the term unchanged.)
3 个评论
Walter Roberson
2023-4-11
At the moment, I do not know of any way to automatically process it into a function handle.
Walter Roberson
2023-4-11
syms y(x) x Y
r=0.05;
m=0.01;
p=1;
s=1;
a=0.25;
b=0.25;
Dy = diff(y);
D2y = diff(y,2);
ode= y-1/x*1/(r-((p*Dy*x*(s^2))/y)+((D2y*x*(s^2))/(2*y))+((Dy*(m-(s^2)))/y))^(1/(1-a-b))
syms dy d2y
temp = subs(ode, {D2y, Dy}, {d2y, dy})
rewritten = subs(isolate(temp==0, d2y), {d2y, dy}, {D2y, Dy})
[eqs,vars] = reduceDifferentialOrder(rewritten,y(x))
[M,F] = massMatrixForm(eqs,vars)
f = M\F
odefun = odeFunction(f,vars)
tspan = [20 80];
ic = [1 0];
[x, y] = ode15s(odefun, tspan, ic);
plot(x, y)
grid
legend(string(f), 'location','best')
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!