필터 지우기
필터 지우기

independent variable shows up as an arrow after using subs

조회 수: 2 (최근 30일)
Joseph Costandy
Joseph Costandy 2017년 3월 24일
답변: Omanshu Thapliyal 2017년 3월 29일
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);

채택된 답변

Omanshu Thapliyal
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개)

카테고리

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