Hi BoostedMan,
It is my understanding that you are trying to calculate the radius at different heights within a cone, dividing the cone into cylinders with varying radii. If the total height of the cone is 'H', and the radius at the base is 'R', then the radius 'r' at any height 'h' from the tip is proportional to 'h', as 'r = (R/H)*h'.
If you're dividing the cone into 'n' horizontal segments (cylinders), each with its own height 'h_i' measured from the tip, and you want to find the radius 'r_i' for each segment, you can use this proportionality. It looks like you're also trying to calculate the area of each cylinder's base.
The following code should correctly calculate the radii and areas for each segment of the cone. Make sure 'R' and 'H' are set to the actual dimensions of your cone.
% Assuming R (radius of the cone's base) and H (height of the cone) are given
R = 2; % Example value
H = 10; % Example value
n = 6; % Number of segments
% Preallocate arrays for efficiency
r = zeros(1, n);
A = zeros(1, n);
for i = 1:n
h_i = (H/n) * i; % Height from the tip for the i-th segment
r(i) = (R / H) * h_i; % Radius at height h_i
A(i) = pi * (r(i))^2; % Area of the i-th segment's base
end
% Display the results
disp('Radii of each segment:');
disp(r);
disp('Area of each segment:');
disp(A);
Kindly have a look at the following documentation links to have more understanding on:
- 'zeros' function: https://www.mathworks.com/help/matlab/ref/zeros.html
- 'disp' function: https://www.mathworks.com/help/dsp/ref/disp.html
Hope that helps!
Balavignesh