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

카테고리

질문:

2017년 11월 23일

댓글:

2017년 11월 23일

Community Treasure Hunt

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

Start Hunting!