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 回表示 (過去 30 日間)
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)
  1 件のコメント
Haseeb Hashim
Haseeb Hashim 2022 年 7 月 20 日
Anyone to help (I just need to know in what order initial conditions are put and the order of columns solution vector) !!!!!!!!!!

サインインしてコメントする。

採用された回答

Sam Chak
Sam Chak 2022 年 7 月 20 日
編集済み: Sam Chak 2022 年 7 月 20 日
@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 = 

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by