MATLAB: Solving a Linear ODE – Help!

differentiallinearodeode45

I have an ode
(2*A*k + 3*G*h(t)^(1/2))*diff(h(t), t) == 2*G*h(t)*(h(t)^(1/2) + (A*k)/G)
that I need to plot as h(t) vs t. ODE45 (and ODE23) returns:
Undefined function 'exist' for input arguments of type 'sym'.
Error in odearguments (line 34)
if exist(ode)==2 && ( nargout(ode)<3 && nargout(ode)~=-1 )
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Solve returns an empty struct, and dSolve returns an implicit answer
ans =
0
root(2*G*z^3 + 2*A*k*z^2 + exp(C24/2 + t), z, 1)^2
or if I raise the MaxDegree to three, six very complex answers with several constants that I don't know how to find. Does anyone know another simple method to solve this ode? Thank you in advance!

Best Answer

Try this:
syms A G k h(t) Y
Eqn = (2*A*k + 3*G*h(t)^(1/2))*diff(h(t), t) == 2*G*h(t)*(h(t)^(1/2) + (A*k)/G)
[ODEF, Subs] = odeToVectorField(Eqn);
DE = matlabFunction(ODEF, 'Vars',{t,Y,[A,G,k]});
A = 0.3; % Provide Correct Values




G = 0.5; % Provide Correct Values
k = 0.7; % Provide Correct Values
h0 = 0.1; % Provide Correct Values
tspan = [0 1]; % Provide Correct Values
[t,y] = ode45(@(t,Y)DE(t,Y,[A,G,k]), tspan, h0);
figure(1)
plot(t, y)
grid