How to build a graph of the solution of a second-order differential equation in MATLAB
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (2)
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.
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
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?
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!