Error in ode45

1 次查看(过去 30 天)
Susmita Panda
Susmita Panda 2023-4-18
i am trying to solve using ode45, however getting error:
Error using odearguments
Inputs must be floats, namely single or double.
Error in ode45 (line 107)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
Error in coupled_ode (line 15)
[t,y] = ode45(ftotal, tspan, ic);
Error in Main (line 13)
[y]=coupled_ode(O, a, g, L, eta, eta_tos ,t_o,T_forced);
I conducted study without "t_o", I got quite good results, but may be getting error due to t_o.

采纳的回答

VBBV
VBBV 2023-4-18
As error suggests that inputs must be of type 'double' , there is a symbolic variable declaration for variable t_o inside the function which is passed as tspan input to ode45. Its possible to avoid such difference by passing the variable directly when calling the function
rng("default")
clc;
close all;
O=rand;
a=rand;
g=9.81;
L=rand;
eta=0.46;
eta_tos=1;
t_o=5;
T_forced=pi/eta_tos;
[t,y]=coupled_ode(O, a, g, L, eta, eta_tos ,t_o,T_forced)
t = 101×1
5.0000 5.0314 5.0628 5.0942 5.1257 5.1571 5.1885 5.2199 5.2513 5.2827
y = 101×4
0 1.0000 0 1.0000 0.0304 0.9210 0.0325 1.0533 0.0571 0.7718 0.0653 1.0219 0.0783 0.5670 0.0958 0.9056 0.0924 0.3255 0.1214 0.7114 0.0986 0.0685 0.1398 0.4529 0.0967 -0.1823 0.1494 0.1494 0.0874 -0.4068 0.1490 -0.1752 0.0716 -0.5874 0.1384 -0.4950 0.0511 -0.7111 0.1182 -0.7838
figure
plot(t, y)
grid
legend('y','Dy','x','Dx')
function [t,y] = coupled_ode(Onum, anum, gnum, Lnum, eta_num, eta_tos_num ,t_o,T_forced)
syms O a g L x(t) y(t) t Y eta_tos eta
dx = diff(x);
d2x = diff(x,2);
dy = diff(y);
d2y = diff(y,2);
Eq1 = d2x == 2*O*sin(a)*dy - (g/L)*x(t)-sin(eta_tos*t_o)+sin(eta*t);
Eq2 = d2y == -2*O*sin(a)*dx - (g/L)*y(t);
[VF,Subs] = odeToVectorField(Eq1, Eq2);
VF = subs(VF,[O a g L eta eta_tos t_o],[Onum anum gnum Lnum eta_num eta_tos_num t_o]);
ftotal = matlabFunction(VF,'Vars',{t,Y});
tspan = [t_o:T_forced/100:(T_forced+t_o)]; % Choose Appropriate Simulation Time
ic = [0 1 0 1]; % Choose Appropriate Initial Conditions
[t,y] = ode45(ftotal,(tspan), ic);
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by