Answer to Question #211908 in MatLAB for Rama

Question #211908

Write a MATLAB code to solve the following problem.

The forced oscillations of a body of mass m on a spring of modulus k are

governed by the ODE

my" +cy' +ky = r

Find the steady-state solution for y(t), if m = 1 kg, c == 0.05g/sec and k =

25 g/sec. Where,

r(t) = {t + pi/2 -pi <= t <= 0; t - pi/2 0 <= t <= pi }

where, r(t) = r(t + 2pi).



1
Expert's answer
2021-06-30T03:14:50-0400
%Main Code
close all,
clear all,
clc,

%{
    The forced oscillations of a body of mass m on a spring of modulus k are
    governed by the ODE     my" +cy' +ky = r
    Find the steady-state solution for y(t), if m = 1 kg, c == 0.05g/sec and k =
    25 g/sec. Where,
    r(t) = {t + pi/2 -pi <= t <= 0; t - pi/2 0 <= t <= pi }
    where, r(t) = r(t + 2pi).
%}


m = 1;
c = 0.05;
k = 25;
t = -pi:0.1:pi;


initial_x    = 0;
initial_dxdt = 0;


[t,y] = ode45( @rhs, t, [initial_x initial_dxdt] )
plot(t,y(:,1));
xlabel('--- t --->'); 
ylabel('--- y --->');
grid on,


function dydt=rhs(t,y)
    m = 1;
    c = 0.05;
    k = 25;
    r=[];
    for n=1:length(t)
        if(t(n)<=0), r(n)= t(n)+(pi/2); end
        if(t(n)>0) , r(n)= t(n)-(pi/2); end       
    end
    dydt_1 = y(2);
    dydt_2 = -(c/m)*y(2) - (k/m)*y(1) + (r/m);
    dydt=[dydt_1; dydt_2];
end


%{
    The forced oscillations of a body of mass m on a spring of modulus k are
    governed by the ODE     my" +cy' +ky = r
    m*d2y/dt2 +c*dy/dt + ky = r
    Find the steady-state solution for y(t), if m = 1 kg, c == 0.05g/sec and k =
    25 g/sec. Where,
    r(t) = {t + pi/2 -pi <= t <= 0; 

            t - pi/2 0 <= t <= pi }    where, r(t) = r(t + 2pi).

%}















Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS