function handle how to apply to dsolve???

syms t y
yp=@(t,y) y-t.^2+1;
exact=dsolve( 'Dy=yp(t,y)', 'y(0)=0.5');
abso=abs(diff(exact,2));
Explicit solution could not be found.
> In dsolve (line 201)
how to change code????

 采纳的回答

syms y(t)
yp = y-t^2+1;
eqn = diff(y) == yp;
ic = y(0) == 1/2;
exact = dsolve([eqn, ic]);
abso = abs(diff(exact,2));
You are causing problems for yourself here and in the previous question by using y as both a function and a variable.

7 个评论

I want to remain function handle.. In your code there is no function handle, isnt it??
syms y t
yp = @(t,y) y-t.^2+1;
yt = sym('y(t)')
exact = dsolve( [diff(yt,t) == subs(yp(t,y), y, yt), 'y(0)=0.5'] );
abso = abs(diff(exact,2));
You are causing problems for yourself here and in the previous question by using y as both a function and a variable.
umm... this code has an error in 2017a. Support of character vectors that are not valid variable names or define a number will be removed in a future release. To create symbolic expressions, first create symbolic variables and then use operations on them.
That is not an error, that is a warning. Other than disabling the warning, there is no solution as long as you insist on using y as both a function and a variable name.
aha.. Thank you! and then, I have a quenstion. In symbolic , function handle is not recommend than symfun??
You have to invoke the function handle on appropriate symbolic variables in order to use it in dsolve() .
Your problem was a conflict between using y as a variable and y as a function.
You had
syms t y
which makes y a variable rather than a function.
You have
yp=@(t,y) y-t.^2+1;
when called with yp(t, y) this gives a result back in terms of the variable y. But in dsolve, you need the function y(t)
Ummm... I must be tired...
syms y(t)
yp = @(t,y) y-t.^2+1;
exact = dsolve([diff(y) == yp(t,y), y(0)==0.5]);
abso = abs(diff(exact,2));
Sorry, and Thank you. I understand my problems and your teaching. Thank you so much!!

请先登录,再进行评论。

更多回答(1 个)

Torsten
Torsten 2017-11-23
Use function handles if you want to integrate numerically, use symbolic expressions if you want to integrate symbolically.
Best wishes
Torsten.

类别

在 帮助中心 和 File Exchange 中查找有关 동적 시스템 모델 的更多信息

Community Treasure Hunt

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

Start Hunting!