How can i fix this error?

조회 수: 1 (최근 30일)
Raul Hrabak
Raul Hrabak 2022년 3월 6일
답변: Matt J 2022년 3월 6일
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)])

답변 (1개)

Matt J
Matt J 2022년 3월 6일
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?

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by