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

 Respuesta aceptada

Walter Roberson
Walter Roberson el 23 de Nov. de 2017
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 comentarios

Seong Ik Kim
Seong Ik Kim el 23 de Nov. de 2017
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 el 23 de Nov. de 2017
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 el 23 de Nov. de 2017
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 el 23 de Nov. de 2017
Editada: Seong Ik Kim el 23 de Nov. de 2017
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 el 23 de Nov. de 2017
Sorry, and Thank you. I understand my problems and your teaching. Thank you so much!!

Iniciar sesión para comentar.

Más respuestas (1)

Torsten
Torsten el 23 de Nov. de 2017

0 votos

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

Preguntada:

el 23 de Nov. de 2017

Comentada:

el 23 de Nov. de 2017

Community Treasure Hunt

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

Start Hunting!