# How to find volume of a curve [f(x)] which is rotated along y-axis?

조회 수: 30(최근 30일)
Kushagra Borse 2021년 11월 7일
편집: Kushagra Borse 2021년 11월 7일
We have a input function y = f(x) and we have to find the volume along x-axis and y-axis. (solid of revolution) The minimum and maximum values of x are given
I am getting the volume along x-axis but I am getting an error while finding the volume along the y-axis.
The values of f(x) and domain is : -
1. x^(1/2), 0<=x<=4
2. 3*cos(0.4*x+pi), -5<=x<=5
3. sin(x)+3, -5<=x<=5
4. x^3, 0<=x<=3
Here is my code
%Volume along x-axis
clc
clear all
syms x y
%fx = input('Enter the function : ')
xmin = input('Enter minimum value of x : ')
xmax = input('Enter maximum value of x : ')
intfx = int((fx)^2,xmin,xmax)
vx = pi*(intfx)
vx = double(vx)
sprintf('The volume along x-axis is %d',vx)
%Volume along y-axis
y_fx_equation_wrt_x = y == fx
x_fy_equation_wrt_y = solve(y_fx_equation_wrt_x, x)
fy = x_fy_equation_wrt_y
ymin = subs(fx,x,xmin)
ymax = subs(fx,x,xmax)
intfy = abs(int(fy^2,ymin,ymax))
vy = pi*(intfy)
vyy = double(vy)
sprintf('The volume along y-axis is %d',vyy)
In output 1 I get an error but on output 2 I don't.
What am I doing wrong?
Output 1
y = 3*cos(0.4*x+pi)
3*cos(0.4*x+pi)
fx =
-3*cos((2*x)/5)
Enter minimum value of x :
-5
xmin =
-5
Enter maximum value of x :
5
xmax =
5
intfx =
(45*sin(4))/4 + 45
vx =
pi*((45*sin(4))/4 + 45)
vx =
114.6241
ans =
'The volume along x-axis is 1.146241e+02'
y_fx_equation_wrt_x =
y == -3*cos((2*x)/5)
x_fy_equation_wrt_y =
(5*pi)/2 - (5*acos(y/3))/2
(5*pi)/2 + (5*acos(y/3))/2
fy =
(5*pi)/2 - (5*acos(y/3))/2
(5*pi)/2 + (5*acos(y/3))/2
ymin =
-3*cos(2)
ymax =
-3*cos(2)
Error using ^ (line 442)
Matrix must be square.
Error in Week6classwork1_2 (line 35)
intfy = abs(int(fy^2,ymin,ymax))
Output 2
y = x^(0.5)
Enter the function :
x^(0.5)
fx =
x^(1/2)
Enter minimum value of x :
0
xmin =
0
Enter maximum value of x :
4
xmax =
4
intfx =
8
vx =
8*pi
vx =
25.1327
ans =
'The volume along x-axis is 2.513274e+01'
y_fx_equation_wrt_x =
y == x^(1/2)
Warning: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
x_fy_equation_wrt_y =
y^2
fy =
y^2
ymin =
0
ymax =
2
intfy =
32/5
vy =
(32*pi)/5
vyy =
20.1062
ans =
'The volume along y-axis is 2.010619e+01'

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

### 답변(1개)

VBBV 2021년 11월 7일
%Volume along x-axis
clc
clear all
syms x y
fx = 3*cos(0.4*x+pi)%;x^(1/2);% 0<=x<=4
fx =
xmin = -5;%input('Enter minimum value of x : ')
xmax = 5;%input('Enter maximum value of x : ')
intfx = int((fx)^2,xmin,xmax);
vx = pi*(intfx);
vx = double(vx);
sprintf('The volume along x-axis is %d',vx)
ans = 'The volume along x-axis is 1.146241e+02'
%Volume along y-axis
y_fx_equation_wrt_x = y == fx;
x_fy_equation_wrt_y = solve(y_fx_equation_wrt_x, x);
fy = x_fy_equation_wrt_y;
ymin = subs(fx,x,xmin);
ymax = subs(fx,x,xmax);
intfy = abs(int(fy.^2,ymin,ymax));
vy = pi*(intfy);
vyy = double(vy);
sprintf('The volume along y-axis is %d',vyy)
ans = 'The volume along y-axis is 0The volume along y-axis is 0'
Use element wise matrix operator
##### 댓글 수: 4표시숨기기 이전 댓글 수: 3
Kushagra Borse 2021년 11월 7일
I rewrite the code and came up with this
%Volume along y-axis
y_fx_equation_wrt_x = y == fx
x_fy_equation_wrt_y = solve(y_fx_equation_wrt_x, x)
fy = x_fy_equation_wrt_y
ymin = subs(fx,x,xmin)
ymax = subs(fx,x,xmax)
if ymin < 0
intfy1 = abs(int(fy(1)^2,ymin,0))
%Taking only one of the equation
vy1 = pi*(intfy1)
vy1 = double(vy1)
intfy2 = abs(int(fy(1)^2,0,ymax))
vy2 = pi*(intfy2)
vy2 = double(vy2)
vy = vy1 + vy2
else
intfy = abs(int(fy(1)^2,ymin,ymax))
vy = pi*(intfy)
vy = double(vy)
end
sprintf('The volume along y-axis is %d',vy)
Now , I believe this is the correct one.
The code isn't running in R2021b so I will just paste my output for y = 3*cos(0.4*x+pi) : -
y_fx_equation_wrt_x =
y == -3*cos((2*x)/5)
x_fy_equation_wrt_y =
(5*pi)/2 - (5*acos(y/3))/2
(5*pi)/2 + (5*acos(y/3))/2
fy =
(5*pi)/2 - (5*acos(y/3))/2
(5*pi)/2 + (5*acos(y/3))/2
ymin =
-3*cos(2)
ymax =
-3*cos(2)
intfy1 =
75*(1 - cos(2)^2)^(1/2) - (75*cos(2))/2 - (75*pi)/4
vy1 =
-pi*((75*pi)/4 + (75*cos(2))/2 - 75*(1 - cos(2)^2)^(1/2))
vy1 =
78.2192
intfy2 =
75*(1 - cos(2)^2)^(1/2) - (75*cos(2))/2 - (75*pi)/4
vy2 =
-pi*((75*pi)/4 + (75*cos(2))/2 - 75*(1 - cos(2)^2)^(1/2))
vy2 =
78.2192
vy =
156.4384
ans =
'The volume along y-axis is 1.564384e+02'
y_fx_equation_wrt_x =
y == -3*cos((2*x)/5)
x_fy_equation_wrt_y =
(5*pi)/2 - (5*acos(y/3))/2
(5*pi)/2 + (5*acos(y/3))/2
fy =
(5*pi)/2 - (5*acos(y/3))/2
(5*pi)/2 + (5*acos(y/3))/2
ymin =
-3*cos(2)
ymax =
-3*cos(2)
intfy1 =
75*(1 - cos(2)^2)^(1/2) - (75*cos(2))/2 - (75*pi)/4
vy1 =
-pi*((75*pi)/4 + (75*cos(2))/2 - 75*(1 - cos(2)^2)^(1/2))
vy1 =
78.2192
intfy2 =
75*(1 - cos(2)^2)^(1/2) - (75*cos(2))/2 - (75*pi)/4
vy2 =
-pi*((75*pi)/4 + (75*cos(2))/2 - 75*(1 - cos(2)^2)^(1/2))
vy2 =
78.2192
vy =
156.4384
ans =
'The volume along y-axis is 1.564384e+02'
y_fx_equation_wrt_x =
y == -3*cos((2*x)/5)
x_fy_equation_wrt_y =
(5*pi)/2 - (5*acos(y/3))/2
(5*pi)/2 + (5*acos(y/3))/2
fy =
(5*pi)/2 - (5*acos(y/3))/2
(5*pi)/2 + (5*acos(y/3))/2
ymin =
-3*cos(2)
ymax =
-3*cos(2)
intfy1 =
75*(1 - cos(2)^2)^(1/2) - (75*cos(2))/2 - (75*pi)/4
vy1 =
-pi*((75*pi)/4 + (75*cos(2))/2 - 75*(1 - cos(2)^2)^(1/2))
vy1 =
78.2192
intfy2 =
75*(1 - cos(2)^2)^(1/2) - (75*cos(2))/2 - (75*pi)/4
vy2 =
-pi*((75*pi)/4 + (75*cos(2))/2 - 75*(1 - cos(2)^2)^(1/2))
vy2 =
78.2192
vy =
156.4384
ans =
'The volume along y-axis is 1.564384e+02'
y_fx_equation_wrt_x =
y == -3*cos((2*x)/5)
x_fy_equation_wrt_y =
(5*pi)/2 - (5*acos(y/3))/2
(5*pi)/2 + (5*acos(y/3))/2
fy =
(5*pi)/2 - (5*acos(y/3))/2
(5*pi)/2 + (5*acos(y/3))/2
ymin =
-3*cos(2)
ymax =
-3*cos(2)
intfy1 =
75*(1 - cos(2)^2)^(1/2) - (75*cos(2))/2 - (75*pi)/4
vy1 =
-pi*((75*pi)/4 + (75*cos(2))/2 - 75*(1 - cos(2)^2)^(1/2))
vy1 =
78.2192
intfy2 =
75*(1 - cos(2)^2)^(1/2) - (75*cos(2))/2 - (75*pi)/4
vy2 =
-pi*((75*pi)/4 + (75*cos(2))/2 - 75*(1 - cos(2)^2)^(1/2))
vy2 =
78.2192
vy =
156.4384
ans =
'The volume along y-axis is 1.564384e+02'
y_fx_equation_wrt_x =
y == -3*cos((2*x)/5)
x_fy_equation_wrt_y =
(5*pi)/2 - (5*acos(y/3))/2
(5*pi)/2 + (5*acos(y/3))/2
fy =
(5*pi)/2 - (5*acos(y/3))/2
(5*pi)/2 + (5*acos(y/3))/2
ymin =
-3*cos(2)
ymax =
-3*cos(2)
intfy1 =
75*(1 - cos(2)^2)^(1/2) - (75*cos(2))/2 - (75*pi)/4
vy1 =
-pi*((75*pi)/4 + (75*cos(2))/2 - 75*(1 - cos(2)^2)^(1/2))
vy1 =
78.2192
intfy2 =
75*(1 - cos(2)^2)^(1/2) - (75*cos(2))/2 - (75*pi)/4
vy2 =
-pi*((75*pi)/4 + (75*cos(2))/2 - 75*(1 - cos(2)^2)^(1/2))
vy2 =
78.2192
vy =
156.4384
ans =
'The volume along y-axis is 1.564384e+02'
As now when ymin = ymax it will just break the integration and add them.

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

### Community Treasure Hunt

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

Start Hunting!

Translated by