Solving Numerical Differential Equation
4 views (last 30 days)
Show older comments
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:
Inputs must be floats, namely single or double.
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
0 Comments
Answers (1)
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
0 Comments
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!