Hello, I am trying to plot the solution to the ordinary second order linear inhomogeneous differential equation:
x''(t)= -x + sin(1.1*t).
I am able to get the solution using the dsolve command, but when I try plotting it using 'plot(x,Solution)', I get an error message saying: 'Warning error updating parametrized function line the following error was reported evaluating the function..' and I can't scroll more to see the full error message.
Any help would be great!

 Respuesta aceptada

Star Strider
Star Strider el 25 de Nov. de 2019

0 votos

Use fplot if you have R2016a or later, ezplot otherwise.

6 comentarios

Louis Sharma
Louis Sharma el 25 de Nov. de 2019
Hi thanks for replying so quick! I forgot to mention that I also tried using fplot but got the same error message..
Star Strider
Star Strider el 25 de Nov. de 2019
My pleasure!
Try this:
syms x(t) t
Dx = diff(x);
Eqn = diff(x,2) == sin(1.1*t) - x;
Xs = dsolve(Eqn, Dx(0) == 0, x(0) == 0) % Include Initial Conditions
figure
fplot(Xs, [0 10])
grid
Louis Sharma
Louis Sharma el 25 de Nov. de 2019
Hi this is great! Thank you so much. This might be a bit much, but since I'm new to Matlab and would like to learn it, could you tell me why my first code didn't work?
Once again thank you!
clear all
syms x(t)
t_min = 0;
t_max= 10;
s = 1.1;
dx = diff(x);
cond_1= x(0) ==1;
cond_2 = dx(0)==0;
conds = [cond_1 cond_2];
ODE= diff(x,t,2) == -x+sin(s*t);
Sol = dsolve(ODE, conds)
Solution = simplify(Sol)
figure
fplot(x,Solution)
Star Strider
Star Strider el 25 de Nov. de 2019
As always, my pleasure!
You did not call fplot correctly. Compare your call to it, and mine.
Call it as:
fplot(Solution, [0 10])
and it works.
Louis Sharma
Louis Sharma el 25 de Nov. de 2019
Amazing! This was really helpful!
Star Strider
Star Strider el 25 de Nov. de 2019
Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Preguntada:

el 25 de Nov. de 2019

Comentada:

el 25 de Nov. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by