hey i want to ask u about tht probelm i found when i was working on my program
it gives me tht problem
Attempted to access w(2); index out of bounds because numel(w)=1.Error in ==> MCC_pp1 at 69e3=w(k+1);
and i will five u my program to help me to correct tht problem plz
clear all;%commande d'une machine cc
% Les parametres --------------------------------------------------
Pn = 3500;wn = 183.26;Van = 240;Ian = 16;Vfn = 300;Ra = 2.581;La = 0.028;Rf = 281.3;Lf = 156;M = 0.9483;J = 0.02215;f = 0.002953;Ka = 1.0113; % 0.9483;
%conditions initiales ----------------------------------------------
Vf = 300; tetaref = 100 * pi / 180;If = Vf / Rf;Ia = 0;w = 1;teta= 0;T = 0.001;Np = 800;% Criteres de conception -------------------------------------------
ts = 0.05; % Settling time < 0.05 second
Mp = 0.05; % Overshoot < 5%
Ess = 0.1; xi = sqrt((log(Mp))^2 / (pi^2 + (log(Mp))^2));wn = - log(Ess) / ( xi * ts );alpha = -1;K=0.5;K1=alpha*wn^2;K2=wn^2+2*xi*wn*alpha;K3=2*xi*wn+alpha;a1=(-Rf/Lf);a2=(-Ra/La);a3=(M/La);a4=(-f/J);a5=(M/J);b1=(1/Lf);b2=(1/La);x1=teta;x2=w;x3=Ia;x4=If;b0=a5*x4*b2;x4_etoile=Vf/Rf;K_0=[K1 K2 K3];%K_0 gain%
Cr=10;C0=(-1/J)*Cr;% calcul des U1 et U2 et V -----------------------------------------
for k = 1:Np Cr = 0; if k >= 400 Cr = 10; end e4=x4-x4_etoile;U2=(1/b1)*((a1*x4)-(K*e4));f=(a4)^2*x1-a4*a5*x3*x4+a4*C0-a5*x4*a2*x3+a3*a5*(x4)^2*x2-a1*a5*x3*x4+a5*x3*b1*U2; e1=teta(k)-tetaref;e2=w(k);e3=w(k+1);e=[e1;e2;e3];V=-(K_0)*e;U1=(1/b0)*(-f+V);If(k+1) = If(k) + T * ( - Rf * If(k) + U2(k) ) / Lf;Ia(k+1) = Ia(k) + T * ( - Ra * Ia(k) - M * If(k) * w(k) + U1(k) ) / La; %#ok<SAGROW>
teta(k+1) = teta(k) + T * w(k); %#ok<SAGROW>Ce(k) = M * If(k) * Ia(k); %#ok<SAGROW>w(k+1) = w(k) + T * ( -f * w(k) + C0(k) - Cr ) / J; %#ok<SAGROW>end;
Best Answer