I am having error using ode45 with Inputs must be floats, namely single or double
2 views (last 30 days)
Show older comments
Hello scholar, I have a code am running and I keep getting this error after several try. what might be the error in my code? Below is the error shown and few lines where the error might have occured. Kindly help
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);
omegap_r = @(r)omegap.*(1-(k_om.*r./a));
eps = @(r)@(omega) eps_inf - (omegap_r(r).^2./(omega.^2+(1i*omega.*gamma)));
opts = odeset('RelTol',1e-5,'AbsTol',1e-8);
[r,eps_bar] = ode45(@(r,eps_bar)@(omega) (eps(r).(omega)-eps_bar).*(eps_bar+2.*eps(r).(omega))./(r.*eps(r).(omega)),tspan,1,opts);
e_a = eps_bar(end)./eps_bar;
epsilon_e = @(omega) eps2+((3*eps2*f(y)).*((e_a(1)-eps2)./(e_a(1)+2*eps2)));
2 Comments
Walter Roberson
on 17 Nov 2021
Please show
whos a eps_inf gamma k_om omega omegap tspan
with tspan being most important for this purpose.
Answers (1)
Steven Lord
on 17 Nov 2021
[r,eps_bar] = ode45(@(r,eps_bar)@(omega) (eps(r).(omega)-eps_bar).*(eps_bar+2.*eps(r).(omega))./(r.*eps(r).(omega)),tspan,1,opts);
The function handle you're passing into ode45 as its first input does not return a numeric value, it instead returns a function handle. This does not satisfy the requirements ode45 imposes on that function, namely that it return a numeric vector.
If you show us the mathematical form of the differential equations you're trying to solve we may be able to offer suggestions for how to modify your ode45 call's first input.
3 Comments
Steven Lord
on 17 Nov 2021
The equation you posted doesn't include omega at all. How does the program "call for omega"?
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!