Holooly Plus Logo

Question 1.9.2: Use the ode45 function to simulate the response to 3x + x + ......

Use the ode 45 function to simulate the response to 3 \ddot{x}+\dot{x}+2 x=0 subject to the initial conditions x(0)=0, \dot{x}(0)=0.25 over the time interval 0 \leq t \leq 20.

The 'Blue Check Mark' means that either the MATLAB code/script/answer provided in the answer section has been tested by our team of experts; or the answer in general has be fact checked.

Learn more on how do we answer questions.

Script File

The first step is to write the equation of motion in first-order form. This yields

\begin{aligned} & \dot{x}_1=x_2 \\ & \dot{x}_2=-\frac{2}{3} x_1-\frac{1}{3} x_2 \end{aligned}

Next, an M-file is created to store the equations of motion. An M-file is created by choosing a name, say, sdof.m, and entering

function xdot = sdof(t,x);
xdot = zeros(2,1);
xdot(1) = x(2);
xdot(2) = –(2/3)*x(1) – (1/3)*x(2);

Next, go to the command mode and enter

t0 = 0;tf = 20;
x0 = [0 0.25];
[t,x] = ode45(‘sdof’,[t0 tf],x0);
plot(t,x)

The first line establishes the initial, (t0), and final, (tf), times. The second line creates the vector containing the initial conditions x0. The third line creates the two vectors t, containing the time history, and x, containing the response at each time increment in t, by calling ode45 applied to the equations set up in sdof. The fourth line plots the vector x versus the vector t. This is illustrated in Figure 1.42.

1.42

Related Answered Questions

Question: 1.10.3

Verified Answer:

The pendulum equation in state-space form is given...
Question: 1.9.4

Verified Answer:

The Mathcad program uses a fixed time step Runge–K...
Question: 1.9.3

Verified Answer:

The Mathematica program uses an iterative method t...
Question: 1.8.1

Verified Answer:

Assume that the springs are undeflected when in th...