How to build a graph of the solution of a second-order differential equation in MATLAB

3 visualizaciones (últimos 30 días)
I need to build a graph for this second order differential equation in MatLab:
φ(t) + (d²φ(t)/dt²) - ((d²φ(t)/dt²) * m * sin(pi) * a) = m * g * sin(pi) * a.
Where a = v * t, v = 1 and m = 0.1.
0 < t < 1 / v.
I tried this:
if true
v = 1;
m = 0.1;
g = 9.81;
syms t phi(t)
eqn = phi(t) + diff(phi, t, 2) - diff(phi, t, 2) * m * sin(pi) * (v * t) == m * g * sin(pi) * (v * t);
phiSolution(t) = dsolve(eqn);
disp(phiSolution(t));
t = linspace(0, 1 / v, 100);
phiValues = double(subs(phiSolution, t));
plot(t, phiValues);
xlabel('t');
ylabel('φ(t)');
title('Graph of φ(t)');
end

Respuestas (2)

Torsten
Torsten el 14 de Feb. de 2024
Movida: Torsten el 14 de Feb. de 2024
Since sin(pi) = 0, your differential equation reduces to
y'' + y = 0
with general solution
a*sin(t) + b*cos(t)
Now incorporate your initial/boundary conditions and you are done.
If you meant "phi" instead of "pi", use ode45.
  3 comentarios
Torsten
Torsten el 14 de Feb. de 2024
Movida: Torsten el 14 de Feb. de 2024
v = 1;
m = 0.1;
g = 9.81;
fun = @(t,y)[y(2);(m*g*sin(y(1))*v*t-y(1))/(1-m*sin(y(1))*v*t)];
tspan = [0 10];
y0 = [0 1];
[T,Y] = ode45(fun,tspan,y0);
plot(T,Y(:,1))

Iniciar sesión para comentar.


Steven Lord
Steven Lord el 14 de Feb. de 2024
Solve the system of ODEs numerically (try using ode45 first, and switch to a stiff solver if it takes too long) rather than symbolically.
Symbolic Math Toolbox has functions to generate the function for use with the numeric ODE solvers from a symbolic expression.
  2 comentarios
Mohamad
Mohamad el 14 de Feb. de 2024
Thanks, I tried ode45 also, but it prints errors too. Can you please provide a code?
Steven Lord
Steven Lord el 14 de Feb. de 2024
Can you show us the code you wrote that tries to solve the problem with ode45 and the full and exact text of the error message you received (all the red text displayed in the Command Window when you ran your code) when you ran that code?

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by