How would I visually represent my State Space Model?

I have made a program to determine the state space model of a ball and beam system. I wanted to visualise the output as I believe a graph is more beneficial than a series of matricies. However, I do not know how.
I was thinking of shoowing the displacement along the beam across time
Below is my program , any advice would be appreciated.
clear;
close all;
clc;
%% Setting Base Parameters %%
m = 0.5; % Allows Input for Mass of Ball %
R = 0.02; % Allows Input for Radius of Ball %
d = 1; % Allows Input for Lever Arm offset of Ball %
g_acc = 9.8; % Sets Value of Gravitational acceleration %
L = 10; % Allows Input for Beam Length %
Mu = 0.35; % Allows Input for Co-efficient of Friction %
Fr = -(Mu*m*g_acc); % Calculates Friction of the Beam %
T = 10; % Allows viewing of system within a specific time frame %
%% Solid Ball System %%
%% Calculation for Solid Ball Transfer Function %%
R2 = R^2;
J = (2/5)*m*R2; % Calculates Moment of Inertia %
s = tf('s');
SB_TF = -(m*g_acc*d)/(L*(J/R2)+m*(s^2))
%% Graphing Transfer Function of Solid Ball %%
%% Linearised State Space Model of Solid Ball %%
H = - m*g_acc/(J/(R^2) + m); % Characteristic Equation %
A = [0 1 0 0;
0 0 H 0;
0 0 0 1;
0 0 0 0];
B = [0 0;
0 ((1/(J/(R^2) + m))*Fr);
0 0;
1 0];
C = [1 0 0 0];
D = 0*C*B;
SB_Fr = ss(A, B, C, D)

9 Comments

Use the lsim function to simulate it, then use those outputs in your plot.
First, be certain that it’s doing what you want it to do —
%% Setting Base Parameters %%
m = 0.5; % Allows Input for Mass of Ball %
R = 0.02; % Allows Input for Radius of Ball %
d = 1; % Allows Input for Lever Arm offset of Ball %
g_acc = 9.8; % Sets Value of Gravitational acceleration %
L = 10; % Allows Input for Beam Length %
Mu = 0.35; % Allows Input for Co-efficient of Friction %
Fr = -(Mu*m*g_acc); % Calculates Friction of the Beam %
T = 10; % Allows viewing of system within a specific time frame %
%% Solid Ball System %%
%% Calculation for Solid Ball Transfer Function %%
R2 = R^2;
J = (2/5)*m*R2; % Calculates Moment of Inertia %
s = tf('s');
SB_TF = -(m*g_acc*d)/(L*(J/R2)+m*(s^2))
SB_TF = -4.9 ----------- 0.5 s^2 + 2 Continuous-time transfer function.
%% Graphing Transfer Function of Solid Ball %%
%% Linearised State Space Model of Solid Ball %%
H = - m*g_acc/(J/(R^2) + m); % Characteristic Equation %
A = [0 1 0 0;
0 0 H 0;
0 0 0 1;
0 0 0 0];
B = [0 0;
0 ((1/(J/(R^2) + m))*Fr);
0 0;
1 0];
C = [1 0 0 0];
D = 0*C*B;
SB_Fr = ss(A, B, C, D)
SB_Fr = A = x1 x2 x3 x4 x1 0 1 0 0 x2 0 0 -7 0 x3 0 0 0 1 x4 0 0 0 0 B = u1 u2 x1 0 0 x2 0 -2.45 x3 0 0 x4 1 0 C = x1 x2 x3 x4 y1 1 0 0 0 D = u1 u2 y1 0 0 Continuous-time state-space model.
figure
pzmap(SB_Fr)
grid
P = pole(SB_Fr)
P = 4×1
0 0 0 0
figure
bodeplot(SB_Fr)
grid
figure
step(SB_Fr)
grid
figure
impulse(SB_Fr)
grid
.
Hi,
Thank-you for the response. I realised an error I made in the code (g should have been negative), please find the corrected version below. I tried using lsim yesterday, but I couldn't get any results.
I was talking to my lecturer and he reccomended usim the tf2ss command found in the following link, https://uk.mathworks.com/help/signal/ref/tf2ss.html
I spend a few hours on it but I couldn't get it to work, do you have any ideas?
Thank-you for your time
clear;
close all;
clc;
%% Setting Base Parameters %%
m = 5; % Allows Input for Mass of Ball %
R = 0.2; % Allows Input for Radius of Ball %
d = 0.3; % Allows Input for Lever Arm offset of Ball %
g_acc = -9.8; % Sets Value of Gravitational acceleration %
L = 5; % Allows Input for Beam Length %
Mu = 0.35; % Allows Input for Co-efficient of Friction %
Fr = (Mu*m*g_acc); % Calculates Friction of the Beam %
T = 10
%% Solid Ball System %%
%% Calculation for Solid Ball Transfer Function %%
R2 = R^2;
J = (2/5)*m*R2; % Calculates Moment of Inertia %
s = tf('s');
SB_TF = -(m*g_acc*d)/(L*(J/R2)+m*(s^2))
%% Graphing Transfer Function of Solid Ball %%
%% Linearised State Space Model of Solid Ball %%
H = - m*g_acc/(J/(R^2) + m); % Characteristic Equation %
A = [0 1 0 0;
0 0 H 0;
0 0 0 1;
0 0 0 0];
B = [0 0;
0 ((1/(J/(R^2) + m))*Fr);
0 0;
1 0];
C = [1 0 0 0];
D = 0*C*B;
SB_Fr = ss(A, B, C, D)
The tf2ss function is from the Signal Propcessing Toolbox. Your function is created with the Control System Toolbox, and the two are not compatible, Just use the ss function to convert ‘SB_TF’ to state space representation.
Thank-you, this makes a lot of sense.
I was aked to interperate the results os the ss model, however I am not sure what the matricies are showing. Hence I was curious about graphing the response.
My pleasure.
I believe your ‘A’ matrix may not be correct.
If possible, could you please elaborate?
The first column and last row are all zeros. That just does not seem correct to me.
Ah ok, I see the concern. I followed and with help from another MATLAB user Sam, modified where nececarry the srcipt found on this tutuorial:
O.K. Since that works, go with it.

Sign in to comment.

Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Release

R2022b

Asked:

Kez
on 14 Nov 2023

Commented:

on 15 Nov 2023

Community Treasure Hunt

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

Start Hunting!