How to Plot a second derivative equation?

Hi all,
The equation I want to plot is
I've tried to gether information online and come up with the code:
clc
clear
syms x(t)
Dx = diff(x);
D2x = diff(x,2);
w = 1
dt = 1/1000;
t = 0:dt:1000*dt;
equ = D2x + (Dx)^3 + x(t)^2 *Dx + x(t) == 0;
figure
fplot(equ)
How to plot the graph with the time interval t?
Edit:
To plot the 2 equation and plot them on the same graph
Can I use the code like this:
syms x_1 x_2 equ(t)
Dx_1 = diff(x_1);
D2x_1 = diff(x_1,2);
Dx_2 = diff(x_2);
D2x_2 = diff(x_2,2);
w_1 = w_2 = 1
a_1 = a_2 = 1
B_1 = B_2 = 1
r_1 = r_2 = 1
equ_1 = D2x_1 + (a_1*(Dx_1) + B_1*x_1^2 - r_1 )*Dx_1 + w_1^2*x_1;
equ_2 = D2x_2 + (a_2*(Dx_2) + B_2*x_2^2 - r_2 )*Dx_2 + w_2^2*x_2;
figure
fimplicit(equ_1, [-1 1]) % Use _fimplicit1 To Plot ‘equ(t)=0’
hold on
fimplicit(equ_2, [-1 1])
grid
Would the graph plot with this code be the solution of the equation?

2 comentarios

Are you sure this is what you want to solve? Given that you have given us the explicit solution for x(t), why not just plot that?
However, I'm not sure that this is correct. Here is your (posulated) solution for x(t):
clear
syms t real
w=1;
x = exp(-1i*w*t) + exp(1i*w*t)
Now, does this satisfy your ODE?
Dx = diff(x,t)
D2x = diff(x,2)
res = D2x + (Dx)^3 + x^2*Dx + x
r = simplify(res)
Now that gives us which does not equal zero like it should for al t.
Guan-Lin Chen
Guan-Lin Chen el 10 de Nov. de 2020
So, can we plot the graph without knowing x(t)?
That is, to plot the
equ = D2x + (Dx)^3 + x(t)^2 *Dx + x(t) == 0;
directly?

Iniciar sesión para comentar.

 Respuesta aceptada

Star Strider
Star Strider el 10 de Nov. de 2020
Try this:
syms x(t) equ(t)
Dx = diff(x);
D2x = diff(x,2);
w = 1
% dt = 1/1000;
% t = 0:dt:1000*dt; % Not needed Here
equ = D2x + (Dx)^3 + x(t)^2 *Dx + x(t);
equ(t) = subs(equ, x, {exp(-1i*w*t)+exp(1i*w*t)}) % Substitute Expression For
figure
fimplicit(equ, [-1 1]) % Use ‘fimplicit’ To Plot ‘equ(t)=0’
grid
The plot is absolutely not interesting, however the code runs without error!

6 comentarios

Guan-Lin Chen
Guan-Lin Chen el 10 de Nov. de 2020
It works!
Thank you!!
Star Strider
Star Strider el 10 de Nov. de 2020
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
Edit:
To plot the 2 equation and plot them on the same graph
Can I use the code like this:
syms x_1 x_2 equ(t)
Dx_1 = diff(x_1);
D2x_1 = diff(x_1,2);
Dx_2 = diff(x_2);
D2x_2 = diff(x_2,2);
w_1 = w_2 = 1
a_1 = a_2 = 1
B_1 = B_2 = 1
r_1 = r_2 = 1
equ_1 = D2x_1 + (a_1*(Dx_1) + B_1*x_1^2 - r_1 )*Dx_1 + w_1^2*x_1;
equ_2 = D2x_2 + (a_2*(Dx_2) + B_2*x_2^2 - r_2 )*Dx_2 + w_2^2*x_2;
figure
fimplicit(equ_1, [-1 1]) % Use _fimplicit1 To Plot ‘equ(t)=0’
hold on
fimplicit(equ_2, [-1 1])
grid
Would the graph plot with this code be the solution of the equation?
No.
First, the other variables need to be declared:
syms x_1 x_2 equ(t) w_2 a_2 B_2 r_2
Dx_1 = diff(x_1);
D2x_1 = diff(x_1,2);
Dx_2 = diff(x_2);
D2x_2 = diff(x_2,2);
w_1 = w_2 == 1;
a_1 = a_2 == 1;
B_1 = B_2 == 1;
r_1 = r_2 == 1;
equ_1 = D2x_1 + (a_1*(Dx_1) + B_1*x_1^2 - r_1 )*Dx_1 + w_1^2*x_1;
equ_2 = D2x_2 + (a_2*(Dx_2) + B_2*x_2^2 - r_2 )*Dx_2 + w_2^2*x_2;
and second, ‘equ_1’ and ‘equ_2’ must be functions of only one variable,. so the others must have scalar numeric values.
Then you can plot them using fimplicit.
Guan-Lin Chen
Guan-Lin Chen el 10 de Nov. de 2020
Thank you!
I use the code and get error like this
Input must be a function or functions of a single variable.
hObj = cellfun(@(f) singleFimplicit(cax,f,limits,extraOpts,args),fn,'UniformOutput',false);
hObj = cellfun(@(f) singleFimplicit(cax,f,limits,extraOpts,args),fn,'UniformOutput',false);
Error in fimplicit (line 126)
hObj = vectorizeFimplicit(cax,fn,limits,extraOpts,args);
How to fix it?
Star Strider
Star Strider el 10 de Nov. de 2020
Quoting from my previous Comment:
‘... and second, ‘equ_1’ and ‘equ_2’ must be functions of only one variable,. so the others must have scalar numeric values.’
That is how to fix it!

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 10 de Nov. de 2020

Comentada:

el 10 de Nov. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by