How can i fix this error?

2 views (last 30 days)
Raul Hrabak
Raul Hrabak on 6 Mar 2022
Answered: Matt J on 6 Mar 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)])

Answers (1)

Matt J
Matt J on 6 Mar 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?

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!