Attempted to access v(0); index must be a positive integer or logical.
Show older comments
clear all, close all, clc;
wetf=@(t,v) -32.2+(((4/15)*(v(t))^2)/(150/32.2));
timerange=[0:30];
initialv=0;
[t1,v1]=ode45(wetf,timerange,initialv)
plot(t1,v1)
I get these errors
Attempted to access v(0); index must be a positive integer or logical.
Error in @(t,v)-32.2+(((4/15)*(v(t))^2)/(150/32.2))
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in stuffthings (line 5)
[t1,v1]=ode45(wetf,timerange,initialv)
HELP!
Answers (1)
Star Strider
on 30 Oct 2015
Your dependent variable is implicitly a function of your independent variable as far as ode45 and its friends are concerned.
Change your function to:
wetf=@(t,v) -32.2 + (4/15).*(v.^2)/(150/32.2);
and your code works.
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!