REG NO. 20BCE3425.pdf - REG NO 20BCE3425 In the second part...

• 13

This preview shows page 1 - 5 out of 13 pages.

REG NO. 20BCE3425
In the second part we give the visualization of the solid of revolution in the 3-D space. Some of the MATLAB commands used in the code are explained here.
int(f(x),a,b) evaluates the integration of f(x) between the limits a and b fx=matlabFunction(f) This converts Symbolic Function f to Anonymous Function fx [X,Y,Z]=cylinder(r); This returns the x- , y- , and z- coordinates of a cylinder using r to define a profile curve. cylinder treats each element in r as a radius at equally spaced heights along the unit height of the cylinder. The cylinder has 20 equally spaced points around its circumference. %Evaluation of Volume of solid of revolution clear all clc syms x f(x)=sqrt(x); % Given function yr=1; % Axis of revolution y=yr I=[0,4]; % Interval of integration a=I(1);b=I(2); vol=pi*int((f(x)-yr)^2,a,b); disp( 'Volume of solid of revolution is: ' ); disp(vol); % Visualization if solid of revolution fx=matlabFunction(f); xv = linspace(a,b,101); % Creates 101 points from a to b [X,Y,Z] = cylinder(fx(xv)-yr); Z = a+Z.*(b-a); % Extending the default unit height of the cylinder profile to the interval of integration. surf(Z,Y+yr,X) % Plotting the solid of revolution about y=yr hold on ; plot([a b],[yr yr], '-r' , 'LineWidth' ,2); % Plotting the line y=yr view(22,11); % 3-D graph viewpoint specification xlabel( 'X-axis' );ylabel( 'Y-axis' );zlabel( 'Z- axis' ); CODE 1 QUESTION: Find the area of the region bounded by the curve y x 2x 2 = and the line y = x . clear clc syms x f(x)=x^2-x*2; % Upper curve g(x)=x; % Lower curve
I=[0,3]; % Interval of Integration a=I(1); b=I(2); A=int(f(x)-g(x),a,b); % Finding the area by integration disp( 'Area bounded by the curves f(x) and g(x) is:' ); disp(A); fplot(f(x),[a,b]);grid on ;hold on ; %Plotting the upper curve fplot(g(x),[a,b]);hold off %Plotting the lower curve xlabel( 'x-axis' );ylabel( 'y- axis' ); legend( 'y=f(x)' , 'y=g(x)' ); OUTPUT Area bounded by the curves f(x) and g(x) is: -9/2 CODE 2 QUESTION: To find the area of the region bounded by the curves y = x 2 , y = x 2 in the first quadrant. clear clc syms x f(x)=sqrt(x); % Upper curve g(x)=x-2; % Lower curve I=[1,4]; % Interval of Integration a=I(1); b=I(2); A=int(f(x)-g(x),a,b); % Finding the area by integration disp( 'Area bounded by the curves f(x) and g(x) is:' ); disp(A); fplot(f(x),[a,b]);grid on ;hold on ; %Plotting the upper curve fplot(g(x),[a,b]);hold off %Plotting the lower curve xlabel( 'x-axis' );ylabel( 'y-axis' ); legend( 'y=f(x)' , 'y=g(x)' ); OUTPUT