dsolve - doesn't work inside a function.
조회 수: 4 (최근 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!