Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help with MATLAB code for 4a and 4b please! Thank you Use the MATLAB function od

ID: 2085369 • Letter: H

Question

Help with MATLAB code for 4a and 4b please! Thank you

Use the MATLAB function ode45 to solve the following second order equation: (a minor modification to the code that we did on Wednesday) mx + cx + kx = f (t) (a) Use the following values and plot x (t) vs t for all the following conditions on the same plot: i. m = 1 kg, k = 900 N/m, c = 0 N s/m, x (0) = 1, x (0) = 0, f (t) = 0 ii. m = 1 kg, k = 900 N/m, c = 5 N s/m, x (0) = 1, x (0) = 0, f (t) = 0 iii. m = 1 kg, k = 900 N/m, c = 20 N s/m, x (0) = 1, x (0) = 0, f (t) = 0 iv. m = 1 kg, k = 900 N/m, c = 40 N s/m, x (0) = 1, x (0) = 0, f (t) = 0 v. m = 1 kg, k = 900 N/m, c = 60 N s/m, x (0) = 1, x (0) = 0, f (t) = 0 (b) Use the following values and plot x(t) vs t for all the following conditions on the same plot. Set m = 1 kg, k = 900 N/m, c = 2 N s/m, x(0) = 1, x = 0. Plot x(t) vs t on the same plot. i. f (t) = cos 10 t ii. f (t) = cos 25 t iii. f (t) = cos 30 t iv. f (t) = cos 45 t v. f (t) = cos 60t (c) Use the following values and plot x (t) vs t for the all the following conditions on the same plot. Set m = 1 kg, k = 90 N/m, c = 2 N s/m, f (t) = 0.

Explanation / Answer

The higher-order ordinary differential equations is first converted into systems of first-order differential equations, and then solve those systems.So lets convert given second order eqn into two first order eqn.

mx''+cx'+kx=f(t) // given 2nd order eqn

lets assume X1= x and X2= x'

differentiate above two eqns separately , we get X1' = x' = X2

and X2' = x'' = f(t) - (c/m)(X2) - (k/m)(X1)

therefore we got two first order equations(in bolded letters) , now lets use ordinary method to solve differential eduation in Matlab using ODE45 solver.

A. m-file:

function xdot=func(t,x)

% have global variables m,c,k,F , these are assumed to be co efficients in given eqn.

xdot(1) = x(2); // these two are the first order equations we obtained from the second order eqn

xdot(2) = F - (c/m)*x(2) - (k/m)*x(1);

xdot = xdot ' ;

command code:

(t,x) = ode45('func',[0 5],[1 0] );

m = 1; //value of m is given as 1kg in A(i)

c = 0; // value of c is given 0Ns/m in A(i)

k = 900; // value of k is given 900n/m in A(i)

F = 0; // value of f(t) is given 0 in a(i)

plot (t ,x(:,10)) ; hold on

m = 1;

c = 5;

k = 900;

F = 0;

plot (t ,x(:,10)) ; hold on

m = 1;

c = 20;

k = 900;

F = 0;

plot (t ,x(:,10)) ; hold on

m = 1;

c = 40;

k = 900;

F = 0;

plot (t ,x(:,10)) ; hold on

m = 1;

c = 60;

k = 900;

F = 0;

plot (t ,x(:,10)) ; hold on  

B. m-file: // set f alone as global variable since it is only the variable here

function xdot=func(t,x)

xdot(1) = x(2);

xdot(2) = F - 2*x(2) - 900*x(1);

xdot = xdot ' ;

command code:

(t,x) = ode45('func',[0 5],[1 0] );

F = cos10t;

plot (t ,x(:,10)) ; hold on

F = cos25t;

plot (t ,x(:,10)) ; hold on

F = cos30t;

plot (t ,x(:,10)) ; hold on

F = cos45t;

plot (t ,x(:,10)) ; hold on

F = cos60t;

plot (t ,x(:,10)) ; hold on

C. m-file: // no need global variable here since all values given constant

function xdot=func(t,x)

xdot(1) = x(2);

xdot(2) = 0 - 2*x(2) - 90*x(1);

xdot = xdot ' ;

command code:

(t,x) = ode45('func',[0 5],[1 0] );

plot (t ,x(:,10)) ; hold on

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote