independent variable shows up as an arrow after using subs
2 次查看(过去 30 天)
显示 更早的评论
After using subs to replace a variable 'u' in an array H with the time dependent function 'u(t)', the array shows '(t -> u(t)) at every occurrence of u in the array. When I then try to solve this array as a system of ODE's using dsolve, the solver fails saying the system does not seem to be linear. If I manually copy the array into the command window, and remove all occurrences of 't ->', the system is solved normally.
To illustrate,
H1=u^2+w;
H2=u+w^2;
dH1du=diff(H1,u);
dH1dw=diff(H1,w);
dH2du=diff(H2,u);
dH2dw=diff(H2,w);
dH=[(dH1du+dH2du);(dH1dw+dH2dw)]
syms u(t) w(t)
dH=subs(dH,[u,w],[u(t),w(t)])
ode1=diff(u)==dH(1);ode2=diff(w)==dH(2);odes=[ode1;ode2]
uw=dsolve(odes)
gives the output:
dH =
2*u + 1
2*w + 1
dH =
2*(t -> u(t)) + 1
2*(t -> w(t)) + 1
odes(t) =
diff(u(t), t) == 2*(t -> u(t)) + 1
diff(w(t), t) == 2*(t -> w(t)) + 1
Error using mupadengine/feval (line 163)
This system does not seem to be linear.
Error in dsolve>mupadDsolve (line 336)
T = feval(symengine,'symobj::dsolve',sys,x,options);
Error in dsolve (line 193)
sol = mupadDsolve(args, options);
Error in matlabwebsitequestion (line 17)
uw=dsolve(odes)
If, instead, I manually replaced the last two lines with the following:
ode1=diff(u)==2*(u(t)) + 1;ode2=diff(w)==2*(w(t)) + 1;odes=[ode1;ode2]
uw=dsolve(odes)
I get the output:
odes(t) =
diff(u(t), t) == 2*u(t) + 1
diff(w(t), t) == 2*w(t) + 1
uw =
w: [1x1 sym]
u: [1x1 sym]
Note that I couldn't declare 'syms u(t) w(t)' from the beginning because I need the partial derivatives of H with respect to these two variables, and if I had declared them with their time functionality from the beginning, I get:
Error using sym/diff (line 26)
All arguments, except for the first one, must not be symbolic functions.
Error in matlabwebsitequestion (line 7)
dH1du=diff(H1,u);
0 个评论
采纳的回答
Omanshu Thapliyal
2017-3-29
This is happening because you probably have symbolic variables 'u' and 'v' declared somewhere a priori. When you do
syms u(t) v(t)
it overwrites the already present 'u' and 'v', which are referred to in the expression
dH=[(dH1du+dH2du);(dH1dw+dH2dw)]
Now when you do 'subs', you are replacing the u in u(t) and not the original u.
The correct way to solve the differential equation would be to replace u and w used before the 'subs' call by some dummy variables, say, 'x' and 'y'.
0 个评论
更多回答(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!