MATLAB: Solving a nonlinear ODE with derivative squared

odeode15s

I'm trying to solve a nonlinear ODE which looks something like this:. I know I can use the implicit solver ode15i but the problem is also stiff so I'd prefer to use ode15s. Is it possible to solve this type of nonlinear ode using ode15s? Any suggestions would be appreciated, thank you!

Best Answer

One approach:
syms a b c d y(t) T Y
Dy = diff(y);
DE = a*Dy^2 + b*Dy + c*y == d;
isoDE = isolate(DE,Dy)
[VF,Sbs] = odeToVectorField(isoDE)
odefcn = matlabFunction(VF, 'Vars',{T,Y,a b c d});
odefcn = @(T,Y,a,b,c,d)[((b+sqrt(a.*d.*4.0+b.^2-a.*c.*Y(1).*4.0)).*(-1.0./2.0))./a; ((b-sqrt(a.*d.*4.0+b.^2-a.*c.*Y(1).*4.0)).*(-1.0./2.0))./a]
a = 3;
b = 5;
c = 7;
d = 11;
[T,Y] = ode15s(@(T,Y)odefcn(T,Y,a,b,c,d), [0 5], [0;0]);
figure
plot(T, Y)
grid
It works!