# I need help with error in code.

1 view (last 30 days)
Anna Zito on 28 Jun 2020
Commented: Geoff Hayes on 29 Jun 2020
I am working on a project and I can not get my program to run without error. I am new to matlab, so it may be something obvious that I am missing.
I was given a set of ODE's from Newton's laws of motion. I solved those ODE's and made them into A and B, seen below.
HERE IS THE WORK & FIGURE ---> PDF
This is the question I am trying to solve with the code below:
Consider a vehicle encountering a single bump that changes the road surface by 0.03m. The excitation can be modeled as a step input magnitude of 0.03 for Xse and using the numerical values in the table, select a suitable time range and time increment to compute the head displacement x1 in cm, and the head acceleration in g's for t=0 to tf, and the relative neck displacement x1-x2 for t=0 to tf.
Compute the system eigenvalues and show how to use them to help determind the final time (tf) and integration time increment so that three oscillations of the largest period can be seen and there are at least 30 time increments for the smallest period.
Plot head displacement vs time on one sheet, relative neck displacement vs time on a separate sheet, and head acceleration (g's) vs time.
I have emailed my professer for help multiple times, and I have not gotten a response for over a week. I just need to know if i am headed in the correct direction to be able to answer all of the given questions. I believe my code looks good so far, but i keep getting error messages.
m1=5.3;
m2=28.5;
m3=8.6;
m4=12.8;
c1=400;
c2=4750;
c3=4585;
c4=4475;
k1=310000;
k2=183000;
k3=162800;
k4=90000;
Input Xse=0.03*ustep(t)
DXse=0.03*d(t)
Let u=Us+UI
Then x=Xs+XI
A=[0 0 0 0 1 0 0 0; 0 0 0 0 0 1 0 0; 0 0 0 0 0 0 1 0; 0 0 0 0 0 0 0 1; -k1/m2 k1/m2 0 0 -c1/m2 c1/m2 0 0; k1/m2 -k1/m2 k2/m2 0 c1/m2 (-(c1/m2)-(c2/m2)) c2/m2 0; 0 k2/m3 (-(k2/m3)-(k3/m3)) k3/m3 0 c2/m3 (-(c2/m3)-(c3/m3)) c3/m3; 0 0 k3/m4 (-(k3/m3)-k4/m4) 0 0 c3/m4 (-(c3/m4)-(c4/m4))];
B=[0 0; 0 0; 0 0; 0 0; 0 0; 0 0; 0 0; c4/m4 k4/m4];
dX=A*x+B*Us
dX=A*x+B*UI
For Us
B=[0 0 0 0 0 0 0 k4/m4];
For UI
B=[0 0 0 0 0 0 0 c4/m4];
##### 3 CommentsShow 1 older commentHide 1 older comment
Geoff Hayes on 29 Jun 2020
Moved Anna's comment to my answer to here
My revised code is shown below. I keep getting the error message:
"Error in Project41 (line 17) Input Xse=0.03*ustep(t)"
Am i using "input" incorrectly? If so, how do I change it so that it will run?
m1=5.3;
m2=28.5;
m3=8.6;
m4=12.8;
c1=400;
c2=4750;
c3=4585;
c4=4475;
k1=310000;
k2=183000;
k3=162800;
k4=90000;
Input Xse=0.03*ustep(t)
DXse=0.03*d(t)
Let u=Us+UI
Then x=Xs+XI
A=[0 0 0 0 1 0 0 0; 0 0 0 0 0 1 0 0; 0 0 0 0 0 0 1 0; 0 0 0 0 0 0 0 1; -k1/m2 k1/m2 0 0 -c1/m2 c1/m2 0 0; k1/m2 -k1/m2 k2/m2 0 c1/m2 (-(c1/m2)-(c2/m2)) c2/m2 0; 0 k2/m3 (-(k2/m3)-(k3/m3)) k3/m3 0 c2/m3 (-(c2/m3)-(c3/m3)) c3/m3; 0 0 k3/m4 (-(k3/m3)-k4/m4) 0 0 c3/m4 (-(c3/m4)-(c4/m4))];
B=[0 0; 0 0; 0 0; 0 0; 0 0; 0 0; 0 0; c4/m4 k4/m4];
dX=A*x+B*Us
D=[0];
Input Xse=0.03*ustep(t)
DXse=0.03*d(t)
Let u=Us+UI
Then x=Xs+XI
dX=A*x+B*Us
Chead=[1 0 0 0 0 0 0 0]
dt= 0.01;
tf=5;
t=0:dt:tf;
%For Us
BS=[0 0 0 0 0 0 k4/m4 0];
[yS,t,x]= step(sys,t) ;
%For UI
BI=[0 0 0 0 0 0 0 c4/m4 ];
[yI,t,x]= impulse(sys,t) ;
Input Xse=0.03*ustep(t)
DXse=0.03*d(t)
Let u=Us+UI
Then x=Xs+XI
dX=A*x+B*Us
Ctorso=[ 0 1 0 0 0 0 0 0];
dt= 0.01;
tf=5;
t=0:dt:tf;
%For Us
BS=[0 0 0 0 0 0 k4/m4 0];
sys=ss(A,BS,ctorso,D)
[yS,t,x]= step(sys,t) ;
%For UI
BI=[0 0 0 0 0 0 0 c4/m4 ];
sys=ss(A,BS,Ctorso,D)
[yI,t,x]= impulse(sys,t);
%Repeat for head acceleration x1double dot using Cheadacc=[-k1/m1 k1/m1 0 0 –c1/m1 c1/m1 0 0] and plot(t,x1doubledot/9.81)
Input Xse=0.03*ustep(t)
DXse=0.03*d(t)
Let u=Us+UI
Then x=Xs+XI
dX=A*x+B*Us
Cheadacc=[-k1/m1 k1/m1 0 0 -c1/m1 c1/m1 0 0];
dt= 0.01;
tf=5;
t=0:dt:tf;
%For Us
BS=[0 0 0 0 0 0 k4/m4 0];
[yS,t,x]= step(sys,t);
%For UI
BI=[0 0 0 0 0 0 0 c4/m4 ];
[yI,t,x]= impulse(sys,t) ;
plot(t,x1doubledot/9.81)
Geoff Hayes on 29 Jun 2020
Anna - how do you want to be using input? Are you asking the user to enter a value? What should be happening with
Input Xse=0.03*ustep(t)
DXse=0.03*d(t)
Let u=Us+UI
Then x=Xs+XI
? What is ustep?