0% found this document useful (0 votes)
7 views4 pages

Chapter10 Prob35

The document discusses the solution of a second-order differential equation for a spring-mass-damper system using MATLAB. It outlines the process of converting the equation into a system of first-order ODEs, implementing user-defined functions, and plotting the results for position and velocity over a specified time interval. Two methods are presented: using a custom function and MATLAB's built-in ode45 function.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Chapter10 Prob35

The document discusses the solution of a second-order differential equation for a spring-mass-damper system using MATLAB. It outlines the process of converting the equation into a system of first-order ODEs, implementing user-defined functions, and plotting the results for position and velocity over a specified time interval. Two methods are presented: using a custom function and MATLAB's built-in ode45 function.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1

10.35 The differential equation for free motion of a spring-mass-damper system is:
d 2x dx
--------2 + 2γ ------ + k 2 x = 0
dt dt
dx
where k 2 = 48 N/m/kg, γ = 0.7 s–1, x ( 0 ) = 0 , and ------ = 0.2 m/s. Solve the ODE over the interval
dt t=0
dx
0 ≤ t ≤ 5 s, and plot x ( t ) and ------ (two separate figures on one page) as a function of t.
dt
(a) Use the user-defined function Sys2ODEsModEU that was written in Problem 10.20. For step size use
0.01 s.
(b) Use one of MATLAB’s built-in functions for solving ODEs.
Solution
To solve the problem the second-order ODE is rewritten as a system of two first-order ODEs. This is done
by introducing a new variable w, such that:
2
dx dw d x
w = ------ and ------- = -------2-
dt dt dt
With these definitions the system of two first-order ODEs is:
dx
------ = w with the initial condition x ( 0 ) = 0
dt
dw
------- = – 2γw – k 2 x with the initial condition w ( 0 ) = 0.2
dt
dx dw
(a) The differential equations ------ = w and ------- = – 2γw – k 2 x are written in a user-defined function called
dt dt
HW10_35aODEs:

function [dxwdt] = HW10_35aODEs(t,x,w)


ksq=48; gamma=0.7;
dxwdt(1)=w;
dxwdt(2)=-2*gamma*w-ksq*x;

The user-defined functions Sys2ODEsModEu (listed in the solution of Problem 10.20) and
HW10_35aODEs are used in the following script file to solve the problem and make the plots.

% HW 10_35a Solution Script


clear, clc
ab=[0 5]; INI=[0 0.2];

Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis
for testing or instructional purposes only to students enrolled in courses for which the textbook
has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the
copyright owner is unlawful.
2

h=0.01;
[t, x, w] = Sys2ODEsModEu(@HW10_35aODEs,ab,h,INI);
subplot(2,1,1)
plot(t,x)
xlabel('Time (s)')
ylabel('Position x (m)')
subplot(2,1,2)
plot(t,w)
xlabel('Time (s)')
ylabel('dx/dt (m/s)')

When the script file is executed the following figure that follows is displayed in the Figure Window.

0.03

0.02
Position x (m)

0.01

-0.01

-0.02
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Time (s)

0.2

0.1
dx/dt (m/s)

-0.1

-0.2
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Time (s)

dx dw
(a) The differential equations ------ = w and ------- = – 2γw – k 2 x are written in a user-defined function called
dt dt
HW10_35bODEs:

Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis
for testing or instructional purposes only to students enrolled in courses for which the textbook
has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the
copyright owner is unlawful.
3

function [dxwdt] = HW10_35bODEs(t,x,w)


ksq=48; gamma=0.7;
dxwdt(1)=w;
dxwdt(2)=-2*gamma*w-ksq*x;

MATLAB built-in function ode45 and HW10_35bODEs are used in the following script file to solve the
problem and make the plots.

% HW 10_35b Solution Script


clear, clc
tspan = [0:0.01:5];
xini = [0 0.2];
[Time x] = ode45(@HW10_35bODEs,tspan,xini);
subplot(2,1,1)
plot(Time,x(:,1))
xlabel('Time (s)')
ylabel('Position (ft)')
subplot(2,1,2)
plot(Time,x(:,2))
xlabel('Time (s)')
ylabel('Velocity (ft/s)')

When the script file is executed the following figure that follows is displayed in the Figure Window.

Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis
for testing or instructional purposes only to students enrolled in courses for which the textbook
has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the
copyright owner is unlawful.
4

0.03

0.02
Position (ft)

0.01

-0.01

-0.02
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Time (s)

0.2

0.1
Velocity (ft/s)

-0.1

-0.2
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Time (s)

Excerpts from this work may be reproduced by instructors for distribution on a not-for-profit basis
for testing or instructional purposes only to students enrolled in courses for which the textbook
has been adopted. Any other reproduction or translation of this work beyond that permitted by
Sections 107 or 108 of the 1976 United States Copyright Act without the permission of the
copyright owner is unlawful.

You might also like