how to display the 3d graph for this problem?
Show older comments
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?
Accepted Answer
More Answers (2)
lakshmi sampath reddy Pulagum
on 1 Dec 2021
0 votes
lakshmi sampath reddy Pulagum
on 1 Dec 2021
0 votes
1 Comment
lakshmi sampath reddy Pulagum
on 1 Dec 2021
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





