Created
December 11, 2023 02:00
-
-
Save Ebrahim-Ramadan/587e727d687e46476f179611daa41dab to your computer and use it in GitHub Desktop.
matlap script to solve first-order ODEs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function solveFirstOrderODE() | |
function dydx = myODE(x, y) | |
dydx = -2 * x * y; %lets say dy/dx=−2xy | |
end | |
% Define the range of x values | |
xspan = [0 5]; % Define the start and end values of x | |
% Define the initial condition y(x0) = y0 | |
x0 = 0; % Initial value of x | |
y0 = 1; % Initial value of y at x0 | |
% Solve the ODE using ode45 | |
[x, y] = ode45(@myODE, xspan, y0); | |
% Plot the solution | |
plot(x, y); | |
xlabel('x'); | |
ylabel('y'); | |
title('Solution of the First-Order ODE: dy/dx = -2*x*y'); % Change the title accordingly | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment