In: Mechanical Engineering
Plot the solution of the equation
6ẏ + y = f(t)
if f (t) = 0 for t + 0 and f(t) = 15 for t ≥ 0. The initial condition is y(0) = 7.
Program plan:
• To write a matlab code to plot the differential equation with the given conditions.
Program:
%**********************************************************
%A matlab code is written to plot the motion of a mass
%connected to a spring with viscous friction on the surface
%with the given condition.
%**********************************************************
%Declaration of function, File name :\'msd.m\'
function xdot = msd(t,x)
%Declaration of global variable
global c f k m
%Declaration of array
A = [0,1;-k/m,-c/m];
%Declaration of array
B = [0;1/m];
%Computes the value
xdot=A*x+B*f;
%End of function
end
%Declaration of variable
global c f k m
%Declaration of constant
m = 3;
%Declaration of constant
c = 18;
%Declaration of constant
k = 102;
%Declaration of constant
f = 10;
%Computes the vales of the function \'msd\'
[t, x] = ode23(\'msd\', [0, 2], [0, 0]);
%Plotting
plot(t,x(:,1)),
%Assigns text to x-axis
xlabel(\'t\'),
%Assigns text to y-axis
ylabel(\'y\')
Outtput:
%Output with different constants m=3,c=39 and k=120
%Output with different constants m=3,c=39 and k=120