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

4 visualizaciones (últimos 30 días)
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 comentarios
Walter Roberson
Walter Roberson el 17 de Nov. de 2021
Please show
whos a eps_inf gamma k_om omega omegap tspan
with tspan being most important for this purpose.
rastors23
rastors23 el 17 de Nov. de 2021
Editada: rastors23 el 17 de Nov. de 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)));

Iniciar sesión para comentar.

Respuestas (1)

Steven Lord
Steven Lord el 17 de Nov. de 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 comentarios
Steven Lord
Steven Lord el 17 de Nov. de 2021
The equation you posted doesn't include omega at all. How does the program "call for omega"?
rastors23
rastors23 el 27 de Nov. de 2021
Editada: Walter Roberson el 27 de Nov. de 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

Iniciar sesión para comentar.

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by