フィルターのクリア

How can I obtain the solution and the derivative of the solution in MuPAD in R2017b

1 回表示 (過去 30 日間)
I'm having some trouble solving a differential equation for both the function and its derivative. Consider the following mupad program: 
eq := f'(t) + 1/f(t) = 2;
dF := solve(eq, f'(t))[1];
field := numeric::ode2vectorfield({f'(t)=dF, f(0)=1}, [f(t), f'(t)]);
sol := numeric::odesolve2(field);
This errors on line 3 with 
Error: The specified differential equations are equivalent to a system of first-order equations in the fields '{f(t)}'. Unable to convert equations to a dynamical system in the specified fields '[f(t), D(f)(t)]'. Specify an ordering of the elements in '{f(t)}' by passing a corresponding list as second argument to 'numeric::ode2vectorfield'. This list determines the ordering of the numeric values returned by 'numeric::odesolve2'. [numeric::ode2vectorfield]
​I need to obtain the solution of the ODE, as well as the derivative of the solution.
How can I do this without this error being thrown?

採用された回答

MathWorks Support Team
MathWorks Support Team 2024 年 4 月 18 日
編集済み: MathWorks Support Team 2024 年 4 月 18 日
This error message indicates that the ODE cannot be converted to a higher order system. This is because the equation is first-order. Thus, it should be solved using one of the methods for solving a first order ODE with an initial condition.
The MuPAD solution is shown below. This solves the equation, takes the derivative of the solution, and substitutes for the solution and the derivative into the original equation to show that they are correct.
eq := f'(t) + 1/f(t) = 2:
o := ode({eq,f(0) = 1},f(t)):
s := solve(o);
d := diff(s[1],t);
simpEqn := subs(eq,f(t) = s[1],f'(t) = d);
Simplify(simpEqn);
Please note that MuPAD is being deprecated, and it is recommended that you transition to using all MATLAB workflows. However, you can use the function "convertMuPADNotebook" to convert MuPAD notebooks into MATLAB Live Scripts automatically. The documentation for this function is linked below:
All of that said, the MATLAB equivalent to the above workflow is shown below:
syms f(t)
eq = diff(f(t), t) + 1/f(t) == sym(2);
s = dsolve(eq,[f(sym(0))==sym(1)])
d = diff(s(1), t)
simpEqn = subs(subs(eq, f(t), s(1)), diff(f(t), t), d)
simplify(simpEqn)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeUtilities for the Solver についてさらに検索

タグ

タグが未入力です。

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by