How can i fix this error?

2 visualizaciones (últimos 30 días)
Raul Hrabak
Raul Hrabak el 6 de Mzo. de 2022
Respondida: Matt J el 6 de Mzo. de 2022
for Z=-4:.5:3
alfa=0;
while alfa<=2*pi
A=[cos(alfa) -sin(alfa) 0;sin(alfa) cos(alfa) 0;0 0 1]; % Matriz de rotación en torno al eje Z
B=A*[(1/5)*sqrt(25+Z^2)+0.5,0,Z]';
x=B(1,1);
y=B(2,1);
z=B(3,1);
plot3(x,y,z,'.r')
hold on
alfa=alfa+pi/100;
end
end
n=linspace(-3,4,10);
dz=n(1,2)-n(1,1);
Vr1=0;
for i=2:101
Vr1=Vr1+pi*(1/5)*sqrt(25+(n(1,i)-dz/2)+0.5)^2*dz;
end
Index in position 2 exceeds array bounds. Index must not exceed 10.
disp(["The volume is:", num2str(Vr1)])

Respuestas (1)

Matt J
Matt J el 6 de Mzo. de 2022
You have a loop running from 2 to 101
for i=2:101
Vr1=Vr1+pi*(1/5)*sqrt(25+(n(1,i)-dz/2)+0.5)^2*dz;
end
but n has only 10 values. Should it have 101 values?

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by