Error in ode45

조회 수: 1 (최근 30일)
Susmita Panda
Susmita Panda 2023년 4월 18일
댓글: Susmita Panda 2023년 4월 19일
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
  댓글 수: 1
Susmita Panda
Susmita Panda 2023년 4월 19일
Got it....Thanks a lot..

댓글을 달려면 로그인하십시오.

추가 답변 (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