- Details
- Parent Category: Programming Assignments' Solutions
We Helped With This MATLAB Programming Assignment: Have A Similar One?

Category | Programming |
---|---|
Subject | MATLAB |
Difficulty | Undergraduate |
Status | Solved |
More Info | Pay For Matlab Homework |
Assignment Description
Need to be done in MATLAB Question (1):
For this question 1 Part (a) code has been given and not sure if it’s done and need part(b) . So here is the code for part (a)
%% Script file project1.m
%% Definition of system parameters: global m c k global x0 v0 m = 1e3; k = 81e3; % c x0 = 1;
v0 = 0;
%% Part (a)
% Plot the time response and total mechanical energy of the SDOF system
% for the different cases of damping being considered.
% Note: Project asks for only the cases of c = [3 18 25]*1e3
% c = 3e3 N.s/m % under-damped case (zeta = 0.167)
% c = 18e3 N.s/m % critically damped case (zeta = 1) % c = 25e3 N.s/m % overdamped case (zeta = 1.389) c_values = [3 18 25]*1e3;
% Plot of the time response figure
for j = 1:length(c_values) c = c_values(j);
% plot the free response normalized with respect to x0 fplot(@(t) frsp_sdof(t)/x0, [0,2]), hold on end hold off
% Set plot parameters % set(gca,'FontSize',12) ax = gca; ax.YLim = [-0.8,1]; ax.XTick = (0:0.2:2); ax.YTick = (-0.8:0.2:1); ax.FontSize = 11; ax.LineWidth = 1;
grid, xlabel('t [sec]'), ylabel('x/x_0 (normalized response)') title({'Time history of the free response of a suspension system', ...
'modeled by a single-degree-of-freedom system'})
LEG = legend('c = 3e3 N-s/m','c = 18e3 N-s/m','c = 25e3 N-s/m'); set(LEG, 'FontSize', 12)
% Plot of the mechanical energy versus time figure
E0 = 0.5*k*x0^2 + 0.5*m*v0^2; % calculate the initial mechanical energy in
[J]
for j = 1:length(c_values) c = c_values(j);
vel = derivative(@(t) frsp_sdof(t)); % define the velocity function
% Define the energy function (E), which is the sum of the potential % and kinectic energies. Normalize E w.r.t. the initial energy E0. E=@(t) (0.5*k*frsp_sdof(t).^2 + 0.5*m*vel(t).^2)/E0; fplot(E, [0,2]), hold on end hold off
% Set plot parameters ax = gca; ax.YLim = [0,1]; ax.XTick = (0:0.2:2); ax.YTick = (0:0.1:1); ax.FontSize = 11; ax.LineWidth = 1; grid, xlabel('t [sec]'), ylabel('E/E_0 (normalized energy)') title({'Time history of the total mechanical energy', ...
'of a suspension system modeled by a SDOF system'}) LEG = legend('c = 3e3 N-s/m','c = 18e3 N-s/m','c = 25e3 N-s/m'); set(LEG, 'FontSize', 12)
%% Part (b)
function x = frsp_sdof(t)
% Free response function of a SDOF system global m c k global x0 v0
wn = sqrt(k/m); % natural frequency ("omega_n") zeta = c/2/sqrt(k*m); % damping ratio wd = wn*sqrt(1-zeta^2); % damped natural frequency ("omega_d")
if zeta == 1; x = x0*exp(-wn*t) + (v0+wn*x0)*t.*exp(-wn*t); % critically damped case else
x = exp(-zeta*wn*t).*(x0*cos(wd*t)+(v0+zeta*wn*x0)/wd*sin(wd*t)); end
function df = derivative(f) sym_f = sym(f);
df = matlabFunction(simplify(diff(sym_f))); % simplify command is optional end
Question (2)
Question (3):