I have an error: Error in 'nonlinear_LQR/S-Function' while executing MATLAB S-function 'fcn_sfcn', flag = 1 (derivatives), at time 0.0." Can someone help me? This is the code:
Afficher commentaires plus anciens
function [sys,x0,str,ts]=...
fnc_sfcn(t,x,u,flag,xinit)
switch flag
case 0
str=[]
ts=[0 0]
s=simsizes
s.NumContStates=6;
s.NumDiscStates=0;
s.NumOutputs=6;
s.NumInputs=3;
s.DirFeedthrough=0;
s.NumSampleTimes=1;
sys=simsizes(s);
x0=[xinit];
case 1
tau=u;
sys=fnc(t,x,tau)
case 3
sys=x;
case {2 4 9}
sys=[];
otherwise
error(['unhandked flag=',num2str(flag)]);
end
Function File:
function xdot= fnc(t,x,tau)
l1=1;l2=1;l3=1;m1=1;m2=1;m3=1;g=10;
xdot = zeros(6,1);
xdot(1)=x(4);
xdot(2)=x(5);
xdot(3)=x(6);
xdot(4)= 1/(l1^2*(m1+m2+m3))*[-( l1*l2*(m2+m3))*xdot(5) - (m3*l1*l3)*xdot(6) + (m1+m2+m3)*g*l1*sin(x(1)) + tau(1) - tau(2)];
xdot(5) = 1/(l2^2*(m2+m3))* [-(l1*l2*(m2+m3))*xdot(4) -( m2*l2*l3)*xdot(6) + (m2+m3)*g*l2*sin(x(2)) + tau(2) - tau(3)];
xdot(6)= 1/(m3*l3^2)*[-(m3*l1*l3)*xdot(4)- (m3*l3*l2)*xdot(5)+(m3*g*l3)*sin(x(3))+tau(3)];
end
1 commentaire
Walter Roberson
le 12 Août 2013
You do not construct x0 or str or ts for any case other than 0. That might be a problem.
Have you considered invoking the debugger?
Réponses (0)
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!