Professional Documents
Culture Documents
Answer.
Source Code.
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;
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.