Error in ode45
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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)
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 Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!