How can I get the analytical solution for this problem?

I'm new to MATLAB, and was asked to get the analytical soltuion for the following function: , however, I'm having a really hard time.
My code was as follows, and I kept recieving an error when I tried to plot:
syms y(x);
ode = diff(y,x) == 2-sqrt(2*x-y+3);
cond = y(0) == 100;
ySol(x) = dsolve(ode,cond);
x = 0:1:100;
plot (x,ySol(x))
In all honestly, I'm not sure if this is the correct method to solving for an analytical soltuion. I would really appreciate any help, and if possible, any guidance on what other resources can help me become more proficient with MATLAB.

 Respuesta aceptada

syms y(x);
ode = diff(y,x) == 2-sqrt(2*x-y+3);
cond = y(0) == 100;
ySol(x) = dsolve(ode,cond);
x = 0:1:100;
ySols = ySol(x);
subplot(1,2,1);
plot(x, real(ySols{1}), 'b', x, imag(ySols{1}), 'r');
legend({'real', 'imaginary'})
title('solution 1')
subplot(1,2,2)
plot(x, real(ySols{2}), 'b', x, imag(ySols{2}), 'r');
legend({'real', 'imaginary'})
title('solution 2')

2 comentarios

Thank you so much for helping with obtaing a graphical solution!
If by any chance you see this, could you please explain to me how you knew/why you used ySols within the commands.
Sorry if this may seem like a basic question, but I'm really just trying to understand where everything comes from because this is the first time I've used Matlab...
I ran the code and saw that executing ySol(x) returned a cell array with two entries, each one a 1 x 100 array of symbols.

Iniciar sesión para comentar.

Más respuestas (1)

madhan ravi
madhan ravi el 14 de Jun. de 2020
Editada: madhan ravi el 14 de Jun. de 2020
It is correct approach. I suggest you to do MATLAB Onramp course and watch Cleve Moler's videos about odes.
P.S: MATLAB is not able to find the analytical solution.

5 comentarios

Thanks for the advice, I've actually watch a few of Moler's videos and they were really helpful. However, I'm still confused on why I only recieve an error when I input the plot command...is there something I'm missing?
See the link in my answer.
Thank you!
R2020a does find an analytic solution. two analytic solutions.
Interesting in 2018b I didn't.

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 14 de Jun. de 2020

Comentada:

el 14 de Jun. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by