plotting matlab state space

15 views (last 30 days)
Marco Boutrus
Marco Boutrus on 31 Mar 2020
Commented: Ameer Hamza on 1 Apr 2020
plotting matlab state space
I am trying to simulate a very simple dynamical system.
mx''+bx'+kx=u(t)
(mx''+cx'+kx=m*9.81)
I want to draw the displacement (position x) and velocity (v) of the system over a time from 0 to 10s with 3 different time stepsizes. i am supposed to work with an A-matrix approach;
ydot = [(-c/m)(-k/m);1 0] [x xdot] +[9.81;0]
i have no idea where to start due to the fact im new to matlab. Here is what i have
clc;
close all;
clear all;
m=7;
c=10;
k=100;
dt=5
t=0:dt:10
A=[(-c/m) (-k/m);1 0 ];
B=[9.81 ; 0];
Any suggestion for completing the code?
Best regards,
Marco
  4 Comments
darova
darova on 31 Mar 2020
as i understood you correctly
Marco Boutrus
Marco Boutrus on 31 Mar 2020
Edited: Marco Boutrus on 31 Mar 2020
let me quote the assignment:
4. Solving numerically:
o Rewrite the equation in state-space form, using the state vector ? = (?). The
end result should look like this:
?̇ = A? + ?
where A is called the system matrix and vector f represents the inhomogeneous term. Find the expressions of the matrix A and vector f. Note that not all terms need to be present, i.e. some matrix or vector elements may be zero.
o Write a Matlab script that solves the equations of motion numerically for the parameter values given to you (group dependent).
N.B.: Use the A-matrix approach as discussed. You will need the script later on for a different system, having a different A-matrix. This way you can re-use your Matlab code.
o Determine the solution of the system above and plot the results for the position and velocity of the mass for t = 0 to 10s using the three different time steps given in the parameter set.
5. Verification/validation
o Check the numerical solution for the different time steps with the analytical
solution. What do you see? Which of the solutions is/are the correct one(s)?
To gain some more insight into the behaviour of the system, we can have a look at the eigenvalues of the A-matrix. This yields valuable information about the behaviour of the system, even before the solution is determined.
o Determine the eigenvalues of the A-matrix and discuss these in comparison to the solutions you have plotted. Check the real and imaginary parts of the eigenvalues and compare those with the results you plotted.
What does the real part of the eigenvalues do to your solution?
What does the imaginary part of the eigenvalues do to the solution? Measure the amplitude and period of the solution and discuss these
values in relation to the eigenvalues.
o What can you say about the contribution of the inhomogeneous term in the
solution?

Sign in to comment.

Answers (1)

Ameer Hamza
Ameer Hamza on 31 Mar 2020
Edited: Ameer Hamza on 31 Mar 2020
Following use ode45 to solve your ODE
dt=5;
t= [0 10];
ic = [0;0]; % initial condition
[t,y] = ode45(@myOdeFcn, t, ic);
plot(t,y);
legend({'Velocity', 'Position'});
function dydt = myOdeFcn(t, y)
m=7;
c=10;
k=100;
A=[(-c/m) (-k/m);1 0 ];
B=[9.81; 0];
dydt = A*y(:)+B;
end
  22 Comments
Marco Boutrus
Marco Boutrus on 1 Apr 2020
ahh yes it was indeed to minor to see with the naked eye.
But i still cant put my finger on the dt=0.5 graph. it goes to an insane displacement and velocity. how can dt change the whole graph in this way?
Ameer Hamza
Ameer Hamza on 1 Apr 2020
This is nothing strange, and it is a well-known fact. All numerical method suffers from this to some extent. Note that Euler is one of the basic numerical methods, so it will be affected the most. See the numerical stability section here: https://en.wikipedia.org/wiki/Euler_method#Numerical_stability

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!