Not able to Understand Code for "Volume of Solid by Revolution"

조회 수: 6 (최근 30일)
Dhairya
Dhairya 2022년 11월 14일
댓글: Dhairya 2022년 11월 15일
clc
clear all
close all
syms x
f = input('Enter the function')
fL = input('Enter the interval on which the function is defined')
yr = input('Enter the axis of rotation')
iL = input('integration limits')
volume = pi*int((f-yr)^2,iL(1),iL(2));
disp(['Volume is: ',num2str(double(volume))])
fx = inline(vectorize(f));
xvals = linspace(fL(1),fL(2),201);
xvals = fliplr(xvals);
xivals = linspace(iL(1),iL(2),201);
xivalsr = fliplr(xivals);
xlim = [fL(1) fL(2)+0.5];
ylim = fx(xlim);
figure('Position',[100 200 560 420])
subplot(2,1,1)
hold on
plot(xvals,fx(xvals),'-b','LineWidth',2);
[X,Y,Z] = cylinder(fx(xivals)-yr,100);
figure('Position',[700 200 560 420])
Z = iL(1) + Z.*(iL(2)-iL(1));
surf(Z,Y+yr,X,'EdgeColor','none','FaceColor','flat','FaceAlpha',0.6);
hold on
plot([iL(1),iL(2)],[yr yr], 'r-', 'LineWidth', 2);
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
view(22,11)
  댓글 수: 1
Dhairya
Dhairya 2022년 11월 14일
please explain this part in the code
[X,Y,Z] = cylinder(fx(xivals)-yr,100);
figure('Position',[700 200 560 420])
Z = iL(1) + Z.*(iL(2)-iL(1));
surf(Z,Y+yr,X,'EdgeColor','none','FaceColor','flat','FaceAlpha',0.6);
hold on
plot([iL(1),iL(2)],[yr yr], 'r-', 'LineWidth', 2);

댓글을 달려면 로그인하십시오.

채택된 답변

Jim Riggs
Jim Riggs 2022년 11월 14일
[X,Y,Z] = cylinder(fx(xivals)-yr,100);
Creates a set of 3D points that define a cylinder
figure('Position',[700 200 560 420])
Creates a figure window, specifying the size and position on the screen
Z = iL(1) + Z.*(iL(2)-iL(1));
Defines variable Z
surf(Z,Y+yr,X,'EdgeColor','none','FaceColor','flat','FaceAlpha',0.6);
Draws a surface plot in the figure window. Specifying the edge color as 'none' Face color is 'flat' and FaceAlpha is 0.6 (The facealpha of 0.6 makes the surfaces partially transparent)
hold on
Turns on 'hold' mode for the figure window, so that the next plot command will be addded to the figure window without erasing the existing figure.
plot([iL(1),iL(2)],[yr yr], 'r-', 'LineWidth', 2);
Adds a line plot to the figure window using, specifying a red color ('r') and a line width of 2.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by