# ode45 Inputs must be floats, namely single or double.

4 views (last 30 days)
Hassan Alkomy on 14 Mar 2019
Commented: Hassan Alkomy on 20 Mar 2019
I Have this code and I do not know where is the problem. I end up with:
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in SixDOFSolutionOnlyFromMaple (line 7)
[t, D]=ode45(@SixDOF14March2019,range,IC);
This is the code (Matlab function) and I want to make it easy for you to follow:
1) I have 5 ODEs which are second order.
2) The 5 ODE varibles are (x, y , z, thx, thy) and their derivatives (xdot, ydot, zdot, thxdot, thydot)
3) I did the summation to calculate some forces.
4) I noticed some thing strang (not sure if it has any effect) that when I want to calculate (DelAL) and the 3 other varibles above it I end up with an expression includes cos(%1) and somethings like that! I do NOT know what is (%1)??!!
function der=SixDOF14March2019(t,D)
x=D(1);
xdot=D(2);
y=D(3);
ydot=D(4);
z=D(5);
zdot=D(6);
thx=D(7);
thxdot=D(8);
thy=D(9);
thydot=D(10);
%thz=D(11);
%thzdot=D(12);
%clear all; close all; clc; format long;
syms x y z thx thy thz xdot ydot zdot thxdot thydot thzdot t Fr Fa J
syms lR lL
syms RjInR RjOutR RjInL RjOutL
syms rIn rOut
syms B
syms thj
syms thinitial
syms alphaO alphaP
syms Pr deltaP Zp
syms omIn omOut omC omB n
syms Nin Nout Nball
syms Ainitial
syms psi
syms Ajb Ab
syms RjOutRFinal RjInRFinal RjOutFinal RjInLFinal
syms DeltajR DelatajAR DeltajRR DeltajL DelatajAL DeltajRL
syms alphajR alphajL
syms deltajR deltajL
syms rgIn rgOut dIn dOut db dm m
syms gamma fin fo SigRhoIn SigRhoOut FRhoIn FRhoOut
syms Ein Eout Eb newIn newOut newB DeltaStarIn DeltaStarOut
syms gammaInitial SigRhoInInitial SigRhoOutInitial FRhoInInitial FRhoOutInitial DeltaStarInInitial DeltaStarOutInitial KInInitial KOutInitial
syms DeltaStarInjR DeltaStarInjL DeltaStarOutjR DeltaStarOutjL
syms M
syms Ix Iy Iz
syms C
% GIVEN:
% ======
g=9.81;
lR=0.1275; lL=0.0875;
rgIn=0.00408;rgOut=0.00461;dIn=0.046; dOut=0.062;db=0.00794;dm=0.5*(dIn+dOut);m=6;
alphaO=15*pi/180;
Ein=(2.07*10^11);Eout=(2.07*10^11);Eb=(2.07*10^11);newIn=0.3;newOut=0.3;newB=0.3;
M=5.5;
Ix=0.05177; Iy=Ix; Iz=0.0044;
psi=0;thinitial=0;
Ainitial=0;
Nin=0;Nout=0;Nball=0;
Pr=50;
n=2500;
omIn=(2*pi*n/60);omOut=0;
B=rgIn+rgOut-db;
alphaP=.273932890990504;
Us = 0.217e-1; Ud = 1.3;
C=300;
%INITIAL CALCULATIONS USING alphaO%
%==================================
gammaInitial=db*cos(alphaO)/dm;
fi=rgIn/db; fo=rgOut/db;
FRhoInInitial= ((1/fi)+(2*gammaInitial/(1-gammaInitial)))/((4)-(1/fi)+(2*gammaInitial/(1-gammaInitial)));
FRhoOutInitial= ((1/fo)-(2*gammaInitial/(1+gammaInitial)))/((4)-(1/fo)-(2*gammaInitial/(1+gammaInitial)));
SigRhoInInitial=(1/db)*((4)-(1/fi)+(2*gammaInitial/(1-gammaInitial)));
SigRhoOutInitial=(1/db)*((4)-(1/fo)-(2*gammaInitial/(1+gammaInitial)));
% DeltaStarInInitial
if (FRhoInInitial>=0)&&(FRhoInInitial<0.9)
DeltaStarInInitial=(-4.473235689079742*(FRhoInInitial^6))+(10.221093192616578*(FRhoInInitial^5))+(-9.137566232244472*(FRhoInInitial^4))+(3.727561235805512*(FRhoInInitial^3))+(-0.911658734913609*(FRhoInInitial^2))+(0.041760021004309*(FRhoInInitial))+(0.999977423957012);
elseif (FRhoInInitial>=0.9)&&(FRhoInInitial<=0.995)
DeltaStarInInitial=(-0.178413900461346*(10^6)*(FRhoInInitial^5))+(0.836143462688479*(10^6)*(FRhoInInitial^4))+(-1.567353804615937*(10^6)*(FRhoInInitial^3))+(1.468900655521535*(10^6)*(FRhoInInitial^2))+(-0.688261350489303*(10^6)*(FRhoInInitial))+(0.128985184237206*(10^6));
elseif (FRhoInInitial>0.995)&&(FRhoInInitial<=1)
DeltaStarInInitial=(-0.283909265667587*(10^12)*(FRhoInInitial^5))+(1.414016787576658*(10^12)*(FRhoInInitial^4))+(-2.817011913800072*(10^12)*(FRhoInInitial^3))+(2.806027557873945*(10^12)*(FRhoInInitial^2))+(-1.397540196512594*(10^12)*(FRhoInInitial))+(0.278417030529744*(10^12));
end
% DeltaStarOutInitial
if (FRhoOutInitial>=0)&&(FRhoOutInitial<0.9)
DeltaStarOutInitial=(-4.473235689079742*(FRhoOutInitial^6))+(10.221093192616578*(FRhoOutInitial^5))+(-9.137566232244472*(FRhoOutInitial^4))+(3.727561235805512*(FRhoOutInitial^3))+(-0.911658734913609*(FRhoOutInitial^2))+(0.041760021004309*(FRhoOutInitial))+(0.999977423957012);
elseif (FRhoOutInitial>=0.9)&&(FRhoOutInitial<=0.995)
DeltaStarOutInitial=(-0.178413900461346*(10^6)*(FRhoOutInitial^5))+(0.836143462688479*(10^6)*(FRhoOutInitial^4))+(-1.567353804615937*(10^6)*(FRhoOutInitial^3))+(1.468900655521535*(10^6)*(FRhoOutInitial^2))+(-0.688261350489303*(10^6)*(FRhoOutInitial))+(0.128985184237206*(10^6));
elseif (FRhoOutInitial>0.995)&&(FRhoOutInitial<=1)
DeltaStarOutInitial=(-0.283909265667587*(10^12)*(FRhoOutInitial^5))+(1.414016787576658*(10^12)*(FRhoOutInitial^4))+(-2.817011913800072*(10^12)*(FRhoOutInitial^3))+(2.806027557873945*(10^12)*(FRhoOutInitial^2))+(-1.397540196512594*(10^12)*(FRhoOutInitial))+(0.278417030529744*(10^12));
end
KInInitial=((4*2^0.5)/3)*(1/(SigRhoInInitial)^0.5)*((Ein*Eb)/(Ein+Eb-(Ein*newB^2)-(Eb*newIn^2)))*(1/DeltaStarInInitial)^1.5
KOutInitial=((4*2^0.5)/3)*(1/(SigRhoOutInitial)^0.5)*((Eout*Eb)/(Eout+Eb-(Eout*newB^2)-(Eb*newOut^2)))*(1/DeltaStarOutInitial)^1.5
KInitial=(1/(((1/KInInitial)^(2/3))+((1/KOutInitial)^(2/3))))^(3/2)
Zp=B*(sin(alphaP-alphaO)/cos(alphaP));
omB=(0.5*dm*db)*((omIn*(1-(db*cos(alphaO)/dm)^2))+(omOut*(1+(db*cos(alphaO)/dm)^2)));
omC=(0.5)*((omIn*(1-(db*cos(alphaO)/dm)))+(omOut*(1+(db*cos(alphaO)/dm))));
thj=(omC*t)+((2*pi*(J-1))/m)+thinitial;
AjInA=(AInA*sin(Nin*(psi+(omC-omIn)*t+(2*pi*(j-1)/m))))+Ainitial;
AjOutA=(AOutA*sin(Nout*(psi+(omC-omOut)*t+(2*pi*(j-1)/m))))+Ainitial;
Ajb=2*Ab*sin(Nball*omB*t);
DelAR=B*sin(alphaO)+Zp+z+lR*(1-cos(thy))*cos(thj)+lR*(1-cos(thx))*cos(thy)*sin(thj)-(1/2)*thy*dm*cos(thj)+(1/2)*thx*dm*sin(thj);
DelAL=B*sin(alphaO)+Zp-z+lL*(1-cos(thy))*cos(thj)+lL*(1-cos(thx))*cos(thy)*sin(thj)+(1/2)*thy*dm*cos(thj)-(1/2)*thx*dm*sin(thj);
% (Initial) Forces:
% =========================
QR = KInitial*deltajR^1.5;
FxR = QR*cos(alphajR)*cos(thj);
FyR = QR*cos(alphajR)*sin(thj);
FzR = QR*sin(alphajR);
MxR = FyR*lR+(1/2)*FzR*sin(thj)*dm;
MyR = FxR*lR+(1/2)*FzR*cos(thj)*dm;
FxxR = symsum(FxR, J, 1, m)
FyyR = symsum(FyR, J, 1, m)
FzzR = symsum(FzR, J, 1, m)
MxxR = symsum(MxR, J, 1, m)
MyyR = symsum(MyR, J, 1, m)
QL = KInitial*deltajL^1.5;
FxL = QL*cos(alphajL)*cos(thj);
FyL = QL*cos(alphajL)*sin(thj);
FzL = QL*sin(alphajL);
MxL = FyL*lL+(1/2)*FzL*sin(thj)*dm;
MyL = FxL*lL+(1/2)*FzL*cos(thj)*dm;
FxxL = symsum(FxL, J, 1, m)
FyyL = symsum(FyL, J, 1, m)
FzzL = symsum(FzL, J, 1, m)
MxxL = symsum(MxL, J, 1, m)
MyyL = symsum(MyL, J, 1, m)
% (Initial) Equations:
% ====================
der=[xdot;
(-1/M)*(C*xdot+FxxR+FxxL-M*g-Us*omIn^2*cos(omIn*t));
ydot;
(-1/M)*(C*ydot+FyyR+FyyL-Us*omIn^2*sin(omIn*t));
zdot;
(-1/M)*(C*zdot+FzzR+FzzL);
thxdot;
(-1/Ix)*(Iz*thydot*omIn+MxxL-MxxR- Ud*omIn^2*cos(omIn*t));
thydot;
(-1/Iy)*(-Iz*thxdot*omIn+MyyL-MyyR- Ud*omIn^2*sin(omIn*t))];
This is the solution code:
clear all; close all; clc; format long;
range=[0 0.1];
IC=[10e-6 0 10e-7 0 10e-8 0 0 0 0 0];
[t, D]=ode45(@SixDOF14March2019,range,IC);
Hassan Alkomy on 20 Mar 2019
Thank you @darova. The code works well now.