Error when plotting a graph

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!

 Accepted Answer

Star Strider
Star Strider on 25 Nov 2019
Use fplot if you have R2016a or later, ezplot otherwise.

6 Comments

Hi thanks for replying so quick! I forgot to mention that I also tried using fplot but got the same error message..
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
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)
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.
Amazing! This was really helpful!
Thank you!

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!