MATLAB: How to Solve differential equation

differential equationsfsolvesolve

Hi all
I have equation like this
dy/dt = a*y^2 + b*y + c
where a, b and c are constant
how can I solve this equation using matlab

Best Answer

I would use ode45 (unless your constants vary significantly in magnitude, then use ode15s).
The code:
a = 0.1; % Create Data


b = 0.2; % Create Data
c = 0.3; % Create Data
f = @(t,y) a.*y.^2 + b.*y + c; % Differential Equation Anonymous Function
tspan = [0 5]; % Time Span
y0 = 0; % Initial Condition
[t,y] = ode45(f, tspan, y0); % Numerically Integrate ‘f(y)’
figure(1)
plot(t,y)
grid
See the documentation for ode45 for details.
Related Question