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

3 Ansichten (letzte 30 Tage)
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

Antworten (2)

Torsten
Torsten am 14 Feb. 2024
Verschoben: Torsten am 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 Kommentare
Torsten
Torsten am 14 Feb. 2024
Verschoben: Torsten am 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))

Melden Sie sich an, um zu kommentieren.


Steven Lord
Steven Lord am 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 Kommentare
Mohamad
Mohamad am 14 Feb. 2024
Thanks, I tried ode45 also, but it prints errors too. Can you please provide a code?
Steven Lord
Steven Lord am 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?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by