dsolve - doesn't work inside a function.
15 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
回答 (2 件)
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'))
0 件のコメント
Kamil
2012 年 2 月 13 日
1 件のコメント
Walter Roberson
2012 年 2 月 13 日
dfun_init = subs(sym('x(t0)=x0'), {'t0', 'x0'}, {t0, x0}));
dsovle(dfun, dfun_init);
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!