I am having error using ode45 with Inputs must be floats, namely single or double

3 views (last 30 days)
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
rastors23
rastors23 on 17 Nov 2021
Edited: rastors23 on 17 Nov 2021
Sorry for the delay in reply, I went off lab before.
a = 1;
tspan = [0.001,a];
f = linspace(0.01,0.1,5);
y = 1:length(f)
omegap = 2.7E14;
eps2 = 1.77;
eps_inf = 1;
gamma = 1E12;
k_om = 0;
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)));

Sign in to comment.

Answers (1)

Steven Lord
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
rastors23
rastors23 on 27 Nov 2021
Edited: Walter Roberson on 27 Nov 2021
clc;
clear all;
close all;
h_bar = 1.054560652E-34/1.6E-19;
k_b = 1.3806488E-23/1.6E-19;
syms omega
d = 10E-9;
a = 1;
tspan = [0.001,a];
f = linspace(0.01,0.1,5);
parfor y = 1:length(f)
T_H = 450; %T1
T_L = 300; %T2
Theta_omega_T_L = @(omega,kp) (h_bar*omega/2).*coth((h_bar*omega)/(2*k_b*T_L));
Theta_omega_T_H = @(omega,kp) (h_bar*omega/2).*coth((h_bar*omega)/(2*k_b*T_H));
THETA = @(omega,kp) Theta_omega_T_H(omega,kp) - Theta_omega_T_L(omega,kp);
%..................Effective..............................%
omegap = 2.7E14;
eps2 = 1.77;
eps_inf = 1;
gamma = 1E12;
k_om = 0.1;
omegap_r = @(r)omegap.*(1-(k_om.*r./a));
eps = @(r) eps_inf - (omegap_r(r).^2./(omega.^2+(1i*omega.*gamma)));
opts = odeset('RelTol',1.e-5,'AbsTol',1.e-8);
[r,eps_bar] = ode45(@(r,eps_bar) (eps(r)-eps_bar).*(eps_bar+2.*eps(r))./(r.*eps(r)),tspan,1,opts);
e_a = eps_bar(end);
epsilon_e = @(omega) eps2+((3*eps2*f(y)).*((e_a(1)-eps2)./(e_a(1)+2*eps2)));
kz = @(omega,kp) sqrt((omega/c).^2-kp.^2);
k_1 = @(omega,kp) sqrt(epsilon_e(omega).*(omega/c).^2-kp.^2);
r_1pp = @(omega,kp)(epsilon_e(omega).*kz(omega,kp)-k_1(omega,kp))./(epsilon_e(omega).*kz(omega,kp)+k_1(omega,kp));
r_1ss = @(omega,kp)(kz(omega,kp)-k_1(omega,kp))./(kz(omega,kp)+k_1(omega,kp));
xi_1 = @(omega,kp)((1 - abs(r_1ss(omega,kp)))^2);
Xi_1 = @(omega,kp) xi_1(omega,kp).*kp.*THETA(omega,kp);
ymin = @(omega) omega/3e8;
XI_1 = integral2(Xi_1,1E13,1E15,1E-5,ymin,'RelTol',1E-3)
end

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!