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 Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by