for k=3:Ns
% 1st derivative
ikd=(it(k+1)-it(k-1))/(2*h);
% 2nd derivative
ikdd=(it(k+1)-2*it(k)+it(k-1))/(h^2);
% Peak current using 1st derivative and 2nd derivative
Ipeak(k)=sqrt(((ikd/wo)^2)+((ikdd/(wo^2))^2))
end
figure(4)
plot(t,Ipeak,'*k',t,Im_correct,'r','LineWidth',1)
title('first and second derivative algorithm')
legend('Calc. Im using 1st derivative and 2nd derivative','Correct Im')
xlabel('Time(s)')
ylabel(' RMS Current (A)')
grid
---------------
Index exceeds array bounds.
Error in First_Second_Derivative (line 11)
ikd=(it(k+1)-it(k-1))/(2*h);

1 comentario

zaid albeik
zaid albeik el 23 de Nov. de 2021
i tryed to put for k=3:Ns -1
but another error apears
Error using plot
Vectors must be the same length.
Error in First_Second_Derivative (line 21)
plot(t,Ipeak,'*k',t,Im_correct,'r','LineWidth',1)

Iniciar sesión para comentar.

Respuestas (1)

Cris LaPierre
Cris LaPierre el 29 de Dic. de 2021

0 votos

We don't know what your variables it, Ns, wo, t, or Im_correct are, so we can't say for certain, but here are some thoughts.
It looks like Ns = length(it) since using Ns-1 in your for-loop counter fixed the exceeding array bounds errors. This is because you index it using k+1, so in the last loop when k=Ns, the index k+1 exceeds the size or it.
As for the new error, this error is because t does not have the same length as either Ipeak or Im_correct. You will need to check your variables to determine which it is. When plotting, each y value has to have a corresponding x value, and vice versa.

Categorías

Preguntada:

el 23 de Nov. de 2021

Respondida:

el 29 de Dic. de 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by