I'm trying to compute the volume of the region between x^2 + y^2 = 1 and x^2 + z^2 = 1. But first I need to draw the cross sections of the region bounded between the two functions in order to get the order of integration, but I'm confused on how to do that.
Here's what I have so far:
r = 1; % radius
n = 200;
[X, Y, Z] = cylinder(r, n);
h = 2; % height
Z = h*Z;
surf(X, Y, Z, 'facecolor', [179/255, 205/255, 227/255], 'LineStyle', 'none')
hold on
fill3(X(2,:), Y(2,:), Z(2,:), [251/255, 180/255, 174/255], 'LineStyle', 'none'); % top
fill3(X(1,:), Y(1,:), Z(1,:), [204/255, 235/255, 197/255], 'LineStyle', 'none'); % bottom
hold off
axis square

 Accepted Answer

In your original earlier post the cylinders were described differently.
Using that definition, I would do something like this (with slightly edited code to plot two distinct concentric cylinders) —
syms x1 y1 x2 y2
x2 = 0.8*x1; % Change As Necessary To Get The Correct Dimensions
y2 = 0.8*y2; % Change As Necessary To Get The Correct Dimensions
cyl = x1^2 + y1^2 - 1;
cyl2 = x2^2 + y2^2 - 1;
figure
hfi1 = fimplicit(cyl);
xv1 = hfi1.XData;
yv1 = hfi1.YData;
hold on
hfi2 = fimplicit(cyl2);
xv2 = hfi2.XData;
yv2 = hfi2.YData;
hold off
axis('equal')
legend('cyl','cyl_2', 'Location','bestoutside')
figure
surf([xv1; xv1], [yv1; yv1], [zeros(size(yv1)); ones(size(yv1))], 'EdgeColor','interp')
hold on
surf([xv2; xv2], [yv2; yv2], [zeros(size(yv2)); ones(size(yv2))], 'EdgeColor','interp')
hold off
grid on
axis('equal')
colormap(turbo)
Make appropriate changes to get the desired results.
.

9 Comments

this really helps. thanks
As always, my pleasure!
The original equations had ‘cyl1’ being defined as a function of ‘x’ and ‘z’, however the relation of ‘z’ and ‘y’ was not defined. Scaling ‘z’ to be a multiple of ‘y’ produced an ellipsoid inside a circle (and an ellipsoidal cylinder inside a circular cylinder). I was not certain what to do with that, so here I made them concentric cylinders. If you define what ‘z’ is with respect to ‘y’, I can change my code to accommodate it.
The two cylinders are at right angles to each other (one oriented vertically and the other horizontally), intersect in the centres of each, and you are calculating the enclosed volume of the intersection. That was not immediately obvious.
In that context, now all your previous posts make sense as well.
My previous code is now changed to something a bit simpler —
[X,Y,Z] = cylinder(1,50);
Z(1,:) = Z(1,:)-2;
Z(2,:) = Z(2,:)+1;
figure
surf(X,Y,Z)
shading('interp')
hold on
surf(X,Z,Y)
% shading('interp')
hold off
grid on
axis('equal')
colormap(turbo)
I believe this more closely approximates what you want to visualise.
.
Perfect, this is exactly it. Thank you
As always, my pleasure!
It was a bit difficult for me to follow the integrations in your hand calculations.
Check to see if this is the correct way of formulating the integrations symbolically:
syms x y z
int1 = int(sqrt(1-z^2),z,0,sqrt(1-y^2))
int1 = 
int2 = int(int1,y,0,sqrt(1-x^2))
int2 = 
int3 = 8*int(int2,x,0,1)
int3 = 
int3 = vpa(int3, 9)
int3 = 
4.4674011
.
This is the way I did it.
syms x y z
f = x^2 + y^2 ==1;
g = x^2 + z^2 ==1;
zbounds = solve(g,z);
ybounds = solve(f,y);
Firststep = int(int(1,z,zbounds(2),zbounds(1)),y,ybounds(2),ybounds(1));
>> int(Firststep,x,-1,1)
Thank you.
I was trying to follow it to see if I could reproduce it.
syms x y z
f = x^2 + y^2 ==1;
g = x^2 + z^2 ==1;
zbounds = solve(g,z)
zbounds = 
ybounds = solve(f,y)
ybounds = 
Firststep = int(int(1,z,zbounds(2),zbounds(1)),y,ybounds(2),ybounds(1))
Firststep = 
Volume = int(Firststep,x,-1,1)
Volume = 
.

Sign in to comment.

More Answers (0)

Products

Release

R2021a

Community Treasure Hunt

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

Start Hunting!