dsolve - doesn't work inside a function.

조회 수: 4 (최근 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 CenterFile Exchange에서 Formula Manipulation and Simplification에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by