You are on page 1of 9

Mindanao State University

General Santos City


College in Engineering

Laboratory Experiment 2: Mathematical Modeling


of Physical Systems
EE 179
Michael B.Ferolin – BSEEN
Objectives: The objective of this exercise is to grasp the important role mathematical
models of physical systems in the design and analysis of control systems. We will learn how
MATLAB helps in solving such models.

Answer.

Source Code.

First write the function in MATLAB

functiondXdt=mass_spring(t, X)
%flow rate
M=750; %(Kg)
B=30; %( Nsec/m)
Fa=300; %N
K=15; %(N/m)
r=1;
% dX/dt
dXdt(1)=X(2);
dXdt(2)=-B/M*X(2)-K/M*X(1)^r+Fa/M;
dXdt=[dXdt(1) ; dXdt(2)]

then write MATLAB code

clc;
clear all;
close all;
X0=[0; 0]; %(initial speed and position)
options = odeset('RelTol',[1e-4 1e-4],'AbsTol',[1e-5 1e-5],'Stats','on');
[t,X]=ode45('mass_spring', [0 200],X0);
subplot 211
plot(t,X(:,1))
subplot 212
plot(t,X(:,2));
xlabel('time')
ylabel('amplitude')

Output.
2.) R=2

functiondXdt=mass_spring(t, X)
%flow rate
M=750; %(Kg)
B=30; %( Nsec/m)
Fa=300; %N
K=15; %(N/m)
r=2;
% dX/dt
dXdt(1)=X(2);
dXdt(2)=-B/M*X(2)-K/M*X(1)^r+Fa/M;
dXdt=[dXdt(1) ; dXdt(2)]
R=3
functiondXdt=mass_spring(t, X)
%flow rate
M=750; %(Kg)
B=30; %( Nsec/m)
Fa=300; %N
K=15; %(N/m)
r=2;
% dX/dt
dXdt(1)=X(2);
dXdt(2)=-B/M*X(2)-K/M*X(1)^r+Fa/M;
dXdt=[dXdt(1) ; dXdt(2)]
3.)
functiondXdt=mass_spring(t, X)
%flow rate
M=750; %(Kg)
B=30; %( Nsec/m)
Fa=300; %N
K=15; %(N/m)
r=1;
% dX/dt
dXdt(1)=X(2);
dXdt(2)=-B/M*X(2)-K/M*X(1)^r+Fa/M;
dXdt=[dXdt(1) ; dXdt(2)]

clc;
X0=[0; 0]; %(initial speed and position)
options = odeset('RelTol',[1e-4 1e-4],'AbsTol',[1e-5 1e-5],'Stats','on');
[t,X]=ode45('mass_spring', [0 200],X0);
position=X(:,1);
speed=X(:,2);
% plot(t,X,'linewidth',3);
figure(1)
hold on
plot(t,X(:,2),'b','linewidth',2)
xlabel('time')
ylabel('amplitude')
title('speed or position at r=1,2 and 3')
Output
Answer

Source Code.

clc
closeall
clearall
num = 1;
denum = [10 0.5 1];
sys = tf(num,denum)
step(sys)

Output.
Conclusion:-

At the end of lab we are able to solve the ordinary differential equation using
MATLAB.
We can find the transfer function of dynamic model in MATLAB easily.
We analyze the speed and position relationship and understand their behavior.
We find and analyze step response of the given system.

You might also like