You are on page 1of 10

Question # 1: Plot the position and the speed in separate graphs.

Source code: %function


function dXdt=mass_spring(t,X) M=705; % (Kg) B=30; % (Nsec/m) Fa=300; % (N) K=15; % (N/m) r=1; % dX/dt dXdt(1,1)=X(2); % Speed dXdt(2,1)=-B/M*X(2)-K/M*X(1)^r+Fa/M; % Displacement % Program code clear all close all clc X0=[0;0];% (Initial speed and position) [t,X]=ode45('mass_spring',[0 200],X0); figure; plot(t,X(:,1)); xlabel('Time(t)'); ylabel('Speed'); title('Mass spring system'); legend('Speed'); grid; figure; plot(t,X(:,2),'r'); xlabel('Time(t)'); ylabel('Position'); title('Mass spring system'); legend('Position'); grid on;

Question # 2: Plot the position and the speed in separate graphs when value of r = 2 & 3.
Source code same as previous with value of r = 2 & 3 When r = 2,

When r = 3,

Question # 3:

Superpose the results and compare with the linear case r=1 and plot all three cases in the same plot window.
Source code: Function 1:
function dXdt=mass_spring(t,X) M=705; % (Kg) B=30; % (Nsec/m) Fa=300; % (N) K=15; % (N/m) r=1; % dX/dt dXdt(1,1)=X(2); % Speed dXdt(2,1)=-B/M*X(2)-K/M*X(1)^r+Fa/M; % Displacement

Function 2:
function dXdt=mass_spring2(t,X) M=705; % (Kg) B=30; % (Nsec/m) Fa=300; % (N) K=15; % (N/m) r=2; % dX/dt dXdt(1,1)=X(2); % Speed dXdt(2,1)=-B/M*X(2)-K/M*X(1)^r+Fa/M; % Displacement

Function 3:
function dXdt=mass_spring3(t,X) M=705; % (Kg) B=30; % (Nsec/m) Fa=300; % (N) K=15; % (N/m) r=3; % dX/dt dXdt(1,1)=X(2); % Speed dXdt(2,1)=-B/M*X(2)-K/M*X(1)^r+Fa/M; % Displacement %program coding clear all close all clc X0=[0;0];% (Initial speed and position) [t,X]=ode45('mass_spring',[0 200],X0); plot(t,X(:,1)); xlabel('Time(t)'); ylabel('Speed'); title('Mass spring system'); hold; X0=[0;0];% (Initial speed and position) [t,X]=ode45('mass_spring2',[0 200],X0); plot(t,X(:,1),'g'); hold on; X0=[0;0];% (Initial speed and position) [t,X]=ode45('mass_spring3',[0 200],X0); plot(t,X(:,1),'r'); legend('r = 1','r = 2','r = 3');

grid on; figure; X0=[0;0];% (Initial speed and position) [t,X]=ode45('mass_spring',[0 200],X0); plot(t,X(:,2),'-'); xlabel('Time(t)'); ylabel('Position'); title('Mass spring system'); hold on; X0=[0;0];% (Initial speed and position) [t,X]=ode45('mass_spring2',[0 200],X0); plot(t,X(:,2),'g'); hold on; X0=[0;0];% (Initial speed and position) [t,X]=ode45('mass_spring3',[0 200],X0); plot(t,X(:,2),'r'); grid on; legend('r = 1','r = 2','r = 3'); title('Mass spring system');

Question # 4: Change the values of each parameters, such as

Compare the results and describe the effects. Answer: Source code and functions are same as question just values are changed. Changing the value of mass M,

When co-efficient of friction B is changed,

When the value of elastic characteristic K is changed,

When Force Fa is changed,

You might also like