I need to know the order of solution vector i-e how solution is stored in solution vector of coupled 2nd order differential equations

1 Ansicht (letzte 30 Tage)
I have these two coupled differential equations
m_1 * z_1_dot_dot + (k_1+k_2 ) z_1 + b * z_1_dot = k_2 * z_2 + b * z_dot_2
m_2 * z_2_dot_dot + k_2 z_2 + b * z_2_dot = k_2 * z_1 + b * z_1_dot + f
( 2 Degree of freedom mass spring system with damping in between Attached image )
Now I have written a code for the solution of these two coupled diffferential equations but I dont know how to write correct initial conditions order (z1 , z_1_dot , z_2 , z_2_dot)
And also I dont know in what order the solution is stored in Solution vector i-e which columns contains the z1 displacement and velocity and which columns contain the displacement and velocity of second z2 (z_2 and z_2_dot)
Here is the Code
clc
clear
close all
% Use Symbolic toolbox
syms m1 m2 k1 k2 f b z1(t) z2(t) t Y;
dz1 = diff(z1);
d2z1 = diff(z1,2);
dz2 = diff(z2);
d2z2 = diff(z2,2);
% Write two Coupled Differential Equations
Eq1 = d2z1 == (k2*z2(t) + b*dz2 - (k1+k2)*z1(t) - b*dz1)/m1; % 1st Equation
Eq2 = d2z2 == (k2*z1(t) + b*dz1 + f - k2*z2(t) - b*dz2)/m2;
% Convert the equations to vector Field (Coupled first order linear differential equations)
[VF,Subs] = odeToVectorField(Eq1, Eq2);
ftotal = matlabFunction(VF,'Vars',{t,Y,m1,m2,k1,k2,f,b});
% Define the Known Parameters
m1 = 10;
m2 = 5;
k1 = 40;
k2 = 20;
b = 10;
f = 5;
% Use ode45 Command to solve the system of coupled equations
tspan = [0 20]; % Choose Appropriate Simulation Time
ic = [0 0 0.3 2]; % Choose Appropriate Initial Conditions (% This is where I need Help The conditions are m1 initial displacement "0.3" and velocity of "2" and for m2 both are zero How do I write in Correct Order)
[t,y] = ode45(@(t,y) ftotal(t,y,m1,m2,k1,k2,f,b), tspan, ic);
% Here t is time vector and y is the solution vector containing solution to
% differential equations
Please please Anyone help and also please make me understand to avoid this confusion in Future.
Any Type of help would be EXTREMELY APPRECIATED !!!!! ( I have given the code which works)

Akzeptierte Antwort

Sam Chak
Sam Chak am 20 Jul. 2022
Bearbeitet: Sam Chak am 20 Jul. 2022
@Haseeb Hashim, Aha, I see.
You will have to remove the semicolon at the end of this line
[VF,Subs] = odeToVectorField(Eq1, Eq2);
so that the output Subs can be displayed and you will know the sequence of the system states. Refer to
For example,
syms f(t) g(t)
eqn1 = diff(g) == g-f;
eqn2 = diff(f,2) == g+f;
eqns = [eqn1 eqn2];
[V,S] = odeToVectorField(eqns)
V = 
S = 

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by