y'' + 3y' + 2y = h(t), y(0) = 1, y'(0) = 0, h(t) = u_π(t), if 0 ≤ t ≤ 10 0, if t > 10. in matlab

To solve the given differential equation with initial conditions using MATLAB, follow these steps:

Step 1: Define the differential equation and the function h(t). Step 2: Define the initial conditions. Step 3: Define the time range over which you want to solve the differential equation. Step 4: Define the right-hand side function, which will be different for 0 ≤ t ≤ 10 and t > 10. Step 5: Use the MATLAB function "ode45" to solve the differential equation.

Here's the MATLAB code to solve the given differential equation:

main.m
% Step 1: Define the differential equation and the function h(t)
syms y(t)
ode = diff(y,t,2) + 3*diff(y,t) + 2*y == piecewise(t <= 10, heaviside(t-pi), t > 10, 0);

% Step 2: Define the initial conditions
cond1 = y(0) == 1;
cond2 = diff(y)(0) == 0;
conds = [cond1, cond2];

% Step 3: Define the time range
tRange = [0, 10];

% Step 4: Define the right-hand side function
h = piecewise(t <= 10, heaviside(t-pi), t > 10, 0);

% Step 5: Solve the differential equation
ySol(t) = dsolve(ode, conds);

% Plot the solution
fplot(ySol, tRange);
xlabel('t');
ylabel('y(t)');
title('Solution of the differential equation');
grid on;
624 chars
25 lines

This code uses the syms function to define symbolic variables, ode45 function to solve the differential equation, piecewise function to define the piecewise function, and fplot function to plot the solution.

The code will plot the solution y(t) on the time range 0 ≤ t ≤ 10.

gistlibby LogSnag