MATLAB: Ode23s Inputs must be floats, namely single or double.

odeode23

hi everyone
i have a problem with ode23s code
How can I fix this problem?
Is anybody here can help me please??
This the fucntion I worte:
function xp = train_feedback(t,x)
% State variable
syms x1 x2 x3 x4 x5 v1 v2 v3 v4 v5;
x = [ x1 , x2 , x3 , x4 , x5 , v1 , v2 , v3 , v4 , v5]';
A = [ 0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 1 -1 0 0 0
0 0 0 0 0 0 1 -1 0 0
0 0 0 0 0 0 0 1 -1 0
0 0 0 0 0 0 0 0 1 -1
0 -12.5 0 0 0 -0.75 0.75 0 0 0
0 62.5 -62.5 0 0 3.75 -7.5 3.75 0 0
0 0 62.5 -62.5 0 0 3.75 -7.5 3.75 0
0 0 0 62.5 -62.5 0 0 3.75 -7.5 3.75
0 0 0 0 62.5 0 0 0 3.75 -3.75];
b1 = [0; 0; 0; 0; 0; 0.005; 0; 0; 0; 0]; % Force Input
b2 = [0; 0; 0; 0; 0; 250; 0; 0; 0; -1250];
vd = 25*(1 - exp(-t/40));
% First Design R = 1/120^2
k = [54.5333 , 16.2848 , -1.3027 , -4.3607 , 191.7414 , -40.4841 , -34.2067 , -29.7070 , -27.3437 , 52.0886];
dx = [x(2)-20 ; x(3)-20 ; x(4)-20 ; x(5)-20];
dv = [x(6)-vd ; x(7)-vd ; x(8)-vd ; x(9)-vd ; x(10)-vd];
z = x(6)-vd;
X = [dx ; dv ; z];
u = -k*X;
xp = A*x + b1*u +b2;
end
And then:
% Feedback LQR
clear
close all
clc
tspan = [0 30];
x0 = [0 ;20 ;20 ;20 ;20 ;0 ;0 ;0 ;0 ;0];
[t , x] = ode23s(@train_feedback , tspan , x0 , ...
odeset('OutputFcn','odeplot','OutputSel',[2:5]));
vd = 25*(1-exp(-t/40));
k = [54.533 , 16.2848 , -1.3027 , -4.3607 , 191.7414 , -40.4841 ,-34.2067 , -29.7070 , -27.3437 , 52.0886];
Ks = 2.5e3;
Ds = 1.5e2;
N = max(size(t));
for i = 1:N
dx = [x(i,2)-20 ; x(i,3)-20 ; x(i,4)-20 ; x(i,5)-20];
dv = [x(i,6)-vd(i) ; x(i,7)-vd(i) ; x(i,8)-vd(i) ; x(i,9)-vd(i) ; x(i,10)-vd(i)];
z = x(i,6)-vd(i);
X(i , :) = [dx;dv;z];
F(i) = -k*X(i,:)';
Fs(:,i) = Ks*dx;
end
figure (1)
subplot(2,1,1)
plot(t,x(:,1)/1000)
grid on
xlabel('Time (sec)')
ylabel('Train Position (Km)')
subplot(2,1,2)
plot(t,vd,t,x(:,6),'-.k')
grid on
xlabel('Time (sec)')
ylabel('Train Velocity (m)')
legend('Desire Velocity','Real Velocity')
set(findall(figure(1),'type','line'),'linewidth',2)
figure(2)
subplot(2,1,1)
plot(t,F,t,Fs(1,:),'-.',t,Fs(4,:),'--')
grid on
xlabel ('Time (sec)')
ylabel ('Force (KN)')
legend ('Input Force','Spring Force 1' , 'Spring Force 4')
subplot(2,1,2)
plot(t,Ds*(x(:,6)-x(:,7)),t,Ds*(x(:,9)-x(:,10)),'-.')
grid on
xlabel ('Time (sec)')
ylabel ('Force (KN)')
legend ('Damping Force 1','Damping Force 4')
set(findall(figure(2),'type','line'),'linewidth',2)
But the program give me this error:
Error using odearguments (line 110)
Inputs must be floats, namely single or double.
Error in ode23s (line 121)
= odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in LQR_modern (line 7)
[t , x] = ode23s(@train_feedback , tspan , x0 , …

Best Answer

Delete these two lines in your function and it works:
syms x1 x2 x3 x4 x5 v1 v2 v3 v4 v5;
x = [ x1 , x2 , x3 , x4 , x5 , v1 , v2 , v3 , v4 , v5]';