Solving Numerical Differential Equation

4 views (last 30 days)
Joy Sodon
Joy Sodon on 12 Dec 2019
Edited: Joy Sodon on 12 Dec 2019
I've tried several different ways to write this with an anonymous function, but I keep getting the same error. I'm not sure if I am missing a small detail or a larger concept as I don't really understand what the error means exactly.
l_d=1.225;
c=1.75;
A=1;
m=10;
g=9.8;
v0=v(0)==0;
dvdt=(m*g-.5*l_d*A*c*(v(t))^2)/m
functanon=@(t,v) dvdt
[ts,vs]=ode45(@(t,v)functanon,[0 4],v0)
Gives the error:
Error using odearguments (line 113)
Inputs must be floats, namely single or double.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);

Answers (1)

Walter Roberson
Walter Roberson on 12 Dec 2019
Use
v0 = 0;
you tried to use an equation as an intial condition, but that can be done only for symbolic differential equations.
dvdt=(m*g-.5*l_d*A*c*(v(t))^2)/m
functanon=@(t,v) dvdt
[ts,vs]=ode45(@(t,v)functanon,[0 4],v0)
should be
dvdt = @(t, v) (m*g-.5*l_d*A*c*(v)^2)/m;
[ts,vs]=ode45(dvdt,[0 4],v0)
But first you have to define l_d

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!