The system is a 2DOF mechanical mass spring damper which is free on one end. The system recieves an input on the free end for a short period of time.
I am trying to solve my system for the equations in X and I am particularly interested in x1(t) and x2(t).
When solving without the conditions dsolve returns a very long function in terms of t and z, I do not know what z is.
clear all
clc
syms x1(t) x2(t) x3(t) x4(t) f2
m1=6.5; %effective mass of the person
m2=2; %mass of the secondary body
c1=60; %effective damping of the person
c2=80; %damping of the second body
k1=150; %effective stiffness of the person
k2=200; %stiffness of the second body
f2 = rectangularPulse(0,.05,5); %impulse input on the secondary body
X = [x1(t); x2(t); x3(t); x4(t)]; %column vector of the states where x1(t) is the position of the person x2(t) is the position of the second body
%x3(t) is the velocity of the first body and x4(t) is the velocity of the second body
A = [0 0 1 0;
0 0 0 1;
-(k1+k2)/m1 k2/m1 -(c1+c2)/m1 c2/m1;
k2/m2 -k2/m2 c2/m2 -c2/m2]; %the system matrix for how the system will behave
B = [0; 0; 0; 1/m2]; %input matrix for how the input affects the system
eqns = diff(X) == A*X + f2*B; %setting the differential system to a variable
cond1 = x1(0)==2; %initial position of the person
cond2 = x2(0)==3; %initial position of the second body
cond3 = x3(0)==6; %initial velocity of the person
cond4 = x4(0)==7; %initial velocity of the second body
conds = [cond1;cond2;cond3;cond4]; %the conditional column vector
[x1Sol(t), x2Sol(t), x3Sol(t), x4Sol(t)] = dsolve(eqns, conds); %setting up the dsolve function to return the equations as done in another forum
x1Sol(t) = simplify(x1Sol(t)) %returning the simplified x1Sol
x2Sol(t) = simplify(x2Sol(t)) %returning the simplified x2Sol
Currently the system coefficients (m1,m2,c1 etc.) and the conditional inputs are set as random placeholders.
I would like the code to work for a symbolic input of f2 as well, as what I am modeling is not simply an impulse.
I just need a useful output for x1Sol(t) and x2Sol(t)
Many thanks,
Carter

 Accepted Answer

If you have the Control System Toolbox, this problem is much easier.
I’m keeping some of your initial symbolic code, however you can dispose of much of it:
syms x1(t) x2(t) x3(t) x4(t) f2
m1=6.5; %effective mass of the person
m2=2; %mass of the secondary body
c1=60; %effective damping of the person
c2=80; %damping of the second body
k1=150; %effective stiffness of the person
k2=200; %stiffness of the second body
f2 = rectangularPulse(0,.05,5); %impulse input on the secondary body
X = [x1(t); x2(t); x3(t); x4(t)]; %column vector of the states where x1(t) is the position of the person x2(t) is the position of the second body
%x3(t) is the velocity of the first body and x4(t) is the velocity of the second body
A = [0 0 1 0;
0 0 0 1;
-(k1+k2)/m1 k2/m1 -(c1+c2)/m1 c2/m1;
k2/m2 -k2/m2 c2/m2 -c2/m2]; %the system matrix for how the system will behave
B = [0; 0; 0; 1/m2]; %input matrix for how the input affects the system
eqns = diff(X) == A*X + f2*B; %setting the differential system to a variable
cond1 = x1(0)==2; %initial position of the person
cond2 = x2(0)==3; %initial position of the second body
cond3 = x3(0)==6; %initial velocity of the person
cond4 = x4(0)==7; %initial velocity of the second body
conds = [cond1;cond2;cond3;cond4]; %the conditional column vector
SSsys = ss(A, B, eye(size(A)), 0); % Use The Control System Toolbox For The Rest Of This
t = linspace(0, 2.5, 150); % Time Vector
u = (t <= 0.5); % Rectangular Pulse
y = lsim(SSsys, u, t, [2; 3; 6; 7]);
figure
plot(t, u, '--b')
hold on
plot(t, y)
hold off
grid
xlabel('Time (s)')
ylabel('Amplitude ()')
legend('Forcing Function', 'position of the person', 'position of the second body', 'velocity of the person', 'velocity of the second body')
Note that ‘x1Sol(t)’ and ‘x2Sol(t)’ are the first two columns of ‘y’, if I understand correctly what you’re doing.
Experiment to get the result you want.

More Answers (1)

Carter McCormick
Carter McCormick on 7 Mar 2019

0 votes

Thank you Star Strider, much appreciated.

Products

Release

R2018b

Community Treasure Hunt

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

Start Hunting!