dsolve - doesn't work inside a function.

15 ビュー (過去 30 日間)
Kamil
Kamil 2012 年 2 月 13 日
How can I solve: dx/dt = f(t,x) , x(t_0) = x_0 using dsolve? (or in any other symbolic way)
If I try typing for example: dsolve('Dx = t^2/x', 'x(0)=1') then everything is ok.
But if I try: f = @(t,x) t^2/x; dsolve('Dx = f', 'x(0)=1') - it doesn't work.
I need this to define some function[] = name(f,...) using dsolve.
Could someone help me?

回答 (2 件)

Walter Roberson
Walter Roberson 2012 年 2 月 13 日
dsolve() only operates on symbolic functions or symbolic expressions, and does not operate on anonymous functions or inline functions.
The expression syntax is different for symbolic functions vs anonymous functions or inline functions, so you cannot use char() to convert the anonymous function to its MATLAB equivalent.
What you need is:
syms t x
ftx = f(t,x); %pass symbolic arguments to the anonymous function!
dfun = subs(sym('Dx = FTX'), 'FTX', ftx);
dsolve(dfun, sym('x(0)=1'))

Kamil
Kamil 2012 年 2 月 13 日
function[ ] = fun(f)
syms t x
ftx = f(t,x); %pass symbolic arguments to the anonymous function!
dfun = subs(sym('Dx = FTX'), 'FTX', ftx);
dsolve(dfun, sym('x(t0)=x0'))
end
And I'm still getting:
> In dsolve at 92 In fun at 5
ans =
[ empty sym ]
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 2 月 13 日
dfun_init = subs(sym('x(t0)=x0'), {'t0', 'x0'}, {t0, x0}));
dsovle(dfun, dfun_init);

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFormula Manipulation and Simplification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by