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

3 views (last 30 days)
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

Answers (2)

Torsten
Torsten on 14 Feb 2024
Moved: Torsten on 14 Feb 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 Comments
Torsten
Torsten on 14 Feb 2024
Moved: Torsten on 14 Feb 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))

Sign in to comment.


Steven Lord
Steven Lord on 14 Feb 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 Comments
Steven Lord
Steven Lord on 14 Feb 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?

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!