0% found this document useful (0 votes)
4 views2 pages

Amc 41

The document presents a MATLAB script that defines and solves a differential equation using the ode45 function. It includes three initial conditions and plots the solutions over a specified time span. The results are displayed in three subplots, each corresponding to a different initial condition.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Amc 41

The document presents a MATLAB script that defines and solves a differential equation using the ode45 function. It includes three initial conditions and plots the solutions over a specified time span. The results are displayed in three subplots, each corresponding to a different initial condition.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

clc; clear; close all;

% Define the differential equation as a function handle


f = @(t, y) -100*y + cos(t)^2;

% Initial condition
y0 = 1;
y1=0.1;
y2=0.01;

% Time span
tspan = [0 50];

% Solve the ODE using ode45


[t, y] = ode45(f, tspan, y0);

% Plot the solution


figure;

subplot(3,1,1)
plot(t, y, "b-", "LineWidth", 2);
xlabel("Time t");
ylabel("Solution y(t)");
title("Solution of dy/dt = 100y + cos(t) using ode45");
grid on;

subplot(3,1,2)
[t, y] = ode45(f, tspan, y1);
plot(t, y, "b-", "LineWidth", 2);
xlabel("Time t");
ylabel("Solution y(t)");
title("Solution of dy/dt = 100y + cos(t) using ode45");
grid on;

[t, y] = ode45(f, tspan, y2);


subplot(3,1,3)
plot(t, y, "b-", "LineWidth", 2);
xlabel("Time t");
ylabel("Solution y(t)");
title("Solution of dy/dt = 100y + cos(t) using ode45");
grid on;

1
Published with MATLAB® R2024b

You might also like