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????

 採用された回答

Walter Roberson
Walter Roberson 2017 年 11 月 23 日

0 投票

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 件のコメント

Seong Ik Kim
Seong Ik Kim 2017 年 11 月 23 日
I want to remain function handle.. In your code there is no function handle, isnt it??
Walter Roberson
Walter Roberson 2017 年 11 月 23 日
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.
Seong Ik Kim
Seong Ik Kim 2017 年 11 月 23 日
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.
Walter Roberson
Walter Roberson 2017 年 11 月 23 日
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.
Seong Ik Kim
Seong Ik Kim 2017 年 11 月 23 日
編集済み: Seong Ik Kim 2017 年 11 月 23 日
aha.. Thank you! and then, I have a quenstion. In symbolic , function handle is not recommend than symfun??
Walter Roberson
Walter Roberson 2017 年 11 月 23 日
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));
Seong Ik Kim
Seong Ik Kim 2017 年 11 月 23 日
Sorry, and Thank you. I understand my problems and your teaching. Thank you so much!!

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

その他の回答 (1 件)

Torsten
Torsten 2017 年 11 月 23 日

0 投票

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

Community Treasure Hunt

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

Start Hunting!