i was able to plot the graph in 2d but in 3d i am unable to plot the graph around the red line
(use this code and execute and see)
clc
clear all
syms x
f = tan(pi*x/4)
fL = [0 1]
yr = 0
iL = [0 1]
finverse(f)
Volume = pi*int((finverse(f))^2,iL(1),iL(2));
disp(['Volume is: ', num2str(double(Volume))])
fx = inline(vectorize(f));
xvals = linspace(fL(1),fL(2),201);
xvalsr = fliplr(xvals);
xivals = linspace(iL(1),iL(2),201);
xivalsr = fliplr(xivals);
xlim = [fL(1)-0.5, fL(2)+0.5];
ylim = fx(xlim);
figure(1)
subplot(2,1,1)
hold on
plot(xvals, fx(xvals),'-b','LineWidth',2)
plot([yr yr],[fL(1) fL(2)],'-r','LineWidth',2)
fill([xvals, xvalsr],[fx(xvals), ones(size(xvalsr))*yr],[0.8 0.8 0.8],'FaceAlpha',0.8)
legend('Function Plot','Axis of Rotation','Filled Region')
title('Function y=f(x) and Region')
xlabel('x-axis')
ylabel('y-axis')
subplot(2,1,2)
hold on
plot(xivals,fx(xivals),'-b','LineWidth',2)
plot(-xivals,fx(xivals),'-m','LineWidth',2)
plot([iL(1) iL(2)],[yr yr],'-r','LineWidth',2)
fill([xivals, xivalsr],[fx(xivals), ones(size(xivalsr))*yr], [0.8 0.8 0.8])
fill([-xivals, -xivalsr],[ones(size(xivals))*yr, fx(xivalsr)], [1 0.8 0.8])
title('Rotated Region in xy-Plane')
xlabel('x-axis')
ylabel('y-axis')
figure(2)
[X,Y,Z] = cylinder(xivals-yr,100);
hold on
Z = iL(1)+ Z.*(iL(2)-iL(1));
surf(Z,Y,X+yr,'EdgeColor','none','FaceColor','flat','FaceAlpha',0.6)
plot([yr yr],[iL(1) iL(2)],'-r','LineWidth',2)
title('Volume generated by revolving a curve about the y-axis')
xlabel('x-axis')
ylabel('y-axis')
zlabel('Z-axis')
view(-22,32)
the code needs correction after the figure(2) line only or maybe before too i may be wrong
can anyone help please?

 채택된 답변

Star Strider
Star Strider 2021년 11월 30일
Try it with these changes —
hs = surf(X,Y,Z,'EdgeColor','none','FaceColor','flat','FaceAlpha',0.6);
hs.ZData = hs.ZData-0.5;
hs.YData = hs.YData+0.5;
rotate(hs, [1 0 0], 90)
I already made them in the code. This just nudges the cone to where it should be, and then rotates it.
syms x
f(x) = tan(pi*x/4)
f(x) = 
fL = [0 1]
fL = 1×2
0 1
yr = 0
yr = 0
iL = [0 1]
iL = 1×2
0 1
finverse(f)
ans(x) = 
Volume = pi*int((finverse(f))^2,iL(1),iL(2));
disp(['Volume is: ', num2str(double(Volume))])
Volume is: 1.2492
fx(x) = f(x); % Inline Is Not Good Programming Practise
xvals = linspace(fL(1),fL(2),201);
xvalsr = fliplr(xvals);
xivals = linspace(iL(1),iL(2),201);
xivalsr = fliplr(xivals);
xlim = [fL(1)-0.5, fL(2)+0.5];
ylim = fx(xlim);
figure(1)
subplot(2,1,1)
hold on
plot(xvals, fx(xvals),'-b','LineWidth',2)
plot([yr yr],[fL(1) fL(2)],'-r','LineWidth',2)
fill([xvals, xvalsr],[fx(xvals), ones(size(xvalsr))*yr],[0.8 0.8 0.8],'FaceAlpha',0.8)
legend('Function Plot','Axis of Rotation','Filled Region')
title('Function y=f(x) and Region')
xlabel('x-axis')
ylabel('y-axis')
subplot(2,1,2)
hold on
plot(xivals,fx(xivals),'-b','LineWidth',2)
plot(-xivals,fx(xivals),'-m','LineWidth',2)
plot([iL(1) iL(2)],[yr yr],'-r','LineWidth',2)
fill([xivals, xivalsr],[fx(xivals), ones(size(xivalsr))*yr], [0.8 0.8 0.8])
fill([-xivals, -xivalsr],[ones(size(xivals))*yr, fx(xivalsr)], [1 0.8 0.8])
title('Rotated Region in xy-Plane')
xlabel('x-axis')
ylabel('y-axis')
figure(2)
[X,Y,Z] = cylinder(xivals-yr,100);
hold on
Z = iL(1)+ Z.*(iL(2)-iL(1));
hs = surf(X,Y,Z,'EdgeColor','none','FaceColor','flat','FaceAlpha',0.6);
hs.ZData = hs.ZData-0.5;
hs.YData = hs.YData+0.5;
rotate(hs, [1 0 0], 90)
plot([yr yr],[iL(1) iL(2)],'-r','LineWidth',2)
title('Volume generated by revolving a curve about the y-axis')
xlabel('x-axis')
ylabel('y-axis')
zlabel('Z-axis')
view(-22,32)
% view(80,30)
grid on
.

댓글 수: 9

but, as you can see,yes thank you for rotating it but the from the fig (1) the second graph you can see that when that function is rotated about y axis the shape dosent match the 3d figure.can you fix it ?
there must be a u-curve cut in it.
there must be a u-curve cut in it.
I have absolutely no idea what that means.
I took a guess as to what the desired result was. If I guessed in error, I will delete my Answer in a few hours, since it will have turned out to not be an Answer after all.
Not the first time for me, and and in all likelihood, definitely not the last.
.
i have checked the points its just a function y=x rotated about y axis can you fix this whole thing please.
it should be y=tan(pi*x/4) about y axis
I still have no idea what that means.
End of my day here. I will delete my Answer tomorrow morning.
Note that the plot, x is on the open interval . If I recall correctly, a cylinder (that would be used for this purpose) only has a positive radius, and in the y direction has values on the closed interval (for all current intents) so rotating the plot around any axis is going to be a problem. The function is an odd function (not symmetric about 0) so simply reflecting the positive portion (as could be done for a curve) is not an option. (This would the the situation for all odd functions, not only .)
How should a cylinder with a negative radius be created and plotted for this purpose?
.
Oh i got it.I am really sorry to waste your precious time. :(.Thank you for answering :).
As always, my pleasure!
No worries, and my time was definitely not wasted in responding to the posted problem. I simply had a great deal of trouble understanding what the desired result is (and I am still not certain that I have).
.

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

추가 답변 (2개)

lakshmi sampath reddy Pulagum
lakshmi sampath reddy Pulagum 2021년 12월 1일

0 개 추천

can you just rotate the function y=tan(pi*x/4) about y-axis or x=0 and plot in 3D.?
lakshmi sampath reddy Pulagum
lakshmi sampath reddy Pulagum 2021년 12월 1일

0 개 추천

I=imread('Capture.png')
imshow(I)

카테고리

Community Treasure Hunt

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

Start Hunting!

Translated by