Error in ode45
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
VBBV
on 18 Apr 2023
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
More Answers (0)
See Also
Categories
Find more on Symbolic Math Toolbox 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!