How to use ode45 to solve coupled second order differential equations
Mostra commenti meno recenti
Hey, I am conducting a frequency analysis on a system of coupled, second order differential equations. I have come up with this code, but I know that it does not solve my system correctly. With a initial condition of (only) y(0) = 0.2, I know from both physical experimentation and from intuition just from looking at the maths, that both of the systems should oscillate and interact with each other. This is not what is seen here, the y graph clearly shows a purely sinusoidal motion, while the other shows the beating behaviour I am looking for. From this, I know that desolve is not solving my problem correctly.
I have seen posts about solving second order DEs with ode45 but I have no idea what is going on, I don't understand the code at all. So my question is, how could I adapt my code to use ode45 to obtain a solution to these two coupled second order differential equations? Would the fourier() function still work, or would I use fft() when I have obtained numerical data?
clear
syms t omega T
syms y(t) z(t)
syms k m w J I
Dy = diff(y);
Dz = diff(z);
k = 4.5682;
m = 0.309 + 0.032*4; %base mass plus extra experimental mass
w = 0.03612;
J = 0.0327;
I = 5.59*10^-3 + 0.032*4*0.155^2; %base rotational inertia plus extra experimental rotational inertia
odes = [diff(y,2) == (-k/m)*y + (w/m)*z; diff(z,2) == (-J/I)*z + (w/I)*y];
cond1 = y(0) == 0.2;
cond2 = Dy(0) == 0;
cond3 = z(0) == 0;
cond4 = Dz(0) == 0;
conds = [cond1 cond2 cond3 cond4];
qwe = dsolve(odes, conds);
wilberforce_y = simplify(qwe.y, 500)
%Fy = simplify(fourier(wilberforce_y), 500)
wilberforce_z = simplify(qwe.z, 500)
%Fz = simplify(fourier(wilberforce_z), 500)
figure
fplot(wilberforce_y, [0 50])
ylim([-1 1])
grid
figure
fplot(wilberforce_z, [0 50])
ylim([-1 1])
grid
% I had some frequency analysis stuff down below, but it is not necessary
% for the question.
10 Commenti
Steven Lord
il 3 Nov 2021
Can you post the mathematical form of the system of ODEs that you're trying to solve? This will help us check the problem from the beginning, making sure that the contents of the odes variable matches the equations you're trying to solve. [If I had a dollar for every time something that I was certain wasn't the problem turned out to be the problem ...]
Amplifying on Steven's comment, dsolve() is correctly solving the differential equations with initial conditions as defined in the problem
clear
syms t omega T
syms y(t) z(t)
syms k m w J I
Dy = diff(y);
Dz = diff(z);
k = 4.5682;
m = 0.309 + 0.032*4; %base mass plus extra experimental mass
w = 0.03612;
J = 0.0327;
I = 5.59*10^-3 + 0.032*4*0.155^2; %base rotational inertia plus extra experimental rotational inertia
odes = [diff(y,2) == (-k/m)*y + (w/m)*z; diff(z,2) == (-J/I)*z + (w/I)*y];
cond1 = y(0) == 0.2;
cond2 = Dy(0) == 0;
cond3 = z(0) == 0;
cond4 = Dz(0) == 0;
conds = [cond1 cond2 cond3 cond4];
qwe = dsolve(odes, conds);
odes = odes(t); % make odes into an array, instead of a function
% Show that the solution satisfies the differential equations
[simplify(diff(qwe.y,t,2) - subs(rhs(odes(1)),[y z],[qwe.y qwe.z])),
simplify(diff(qwe.z,t,2) - subs(rhs(odes(2)),[y z],[qwe.y qwe.z]))]
% Show that the solution satisfes the initial conditions
simplify(subs([qwe.y qwe.z diff(qwe.y) diff(qwe.z)],t,0))
Star Strider
il 4 Nov 2021
Bjorn Gustavsson
il 4 Nov 2021
The ideal Wilberforce pendulum (i.e. without any damping-factors) leads to two coupled second-order ODEs. They have rather standard harmonic solutions, but rather tedious initial condition set-up: Wilberforce pendulum paper
Luke Weston
il 4 Nov 2021
Bjorn Gustavsson
il 4 Nov 2021
You could for example take a look at the energy in the two modes (potential and kinetic energy of y and z respectively and look at how the effect of the coupling constant impact the variation of them). You could also take a look at how damping-factors impact the solutions (the original equations are ideal with no dissipation, but where I live everything comes to rest eventually). For that it seems that the symbolic toolbox struggles a bit, dsolve produces solutions with "Root(..." that are difficult to push further, it is possible to calculate the eigenvectors and eigen-values to the 4-by-4 fundamental matrix of the system of equations - but the expressions in them are "rather long". But you might still get some interesting behaviour with numerical solutions.
Paul
il 4 Nov 2021
Getting back to @Steven Lord's comment, are these the correct equations for the Wilberforce pendulum? Should the last terms on the rhs of the equations be:
+ (-w/m)*z*y
adn
+ (-w/I)*z*y
Bjorn Gustavsson
il 4 Nov 2021
@Paul and @Luke Weston: Check equations 2 and 3 in the paper I linked to above. There seems to be a sign-error in the ODEs above, but the coupling-terms are linear.
Paul
il 4 Nov 2021
Interesting. This reference has the nonlinear terms I cited, but that seems to be an error when they pulled the equations from the the exact reference that you (@Bjorn Gustavsson) cite. I agree that the sign in those terms in the ODEs in the Question should be reversed. At least I had that part correct ;).
Bjorn Gustavsson
il 5 Nov 2021
The way I understood the system is that when a spring (coil) is twisted it also changes its length, and for that type of system a simlpe linear coupling seems to make sense. Perhaps the sign of the coupling-constant depends on the direction of the angular variable - with or against the direction of the spiral.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Ordinary Differential Equations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!