# mat shantanu2.odt - Experiment 2 1 Find the area of the...

• 4

This preview shows page 1 - 3 out of 4 pages.

Experiment 2 1. Find the area of the region bounded by the curve y=x 2 -2x and the line y=x. MATLAB CODE :- clear all clc syms x f=input( 'Enter the upper curve f(x): ' ); g=input( 'Enter the lower curve g(x): ' ); L=input( 'Enter the limits of integration for x [a,b]:' ); a=L(1); b=L(2); Area=int(f-g,x,a,b); disp([ 'Area bounded by the curves f(x) and g(x) is: ' ,char(Area)]); x1=linspace(a,b,20);y1=subs(f,x,x1); x2=x1;y2=subs(g,x,x1); plot(x1,y1);hold on ; plot(x2,y2);hold off ; xlabel( 'x-axis' );ylabel( 'y-axis' ); legend( 'f(x)' , 'g(x)' );grid on ; MATLAB OUTPUT:- Enter the upper curve f(x): x^2-2*x Enter the lower curve g(x): x Enter the limits of integration for x [a,b]:[0,3] Area bounded by the curves f(x) and g(x) is: -9/2 GRAPH:-
2. Find the volume of a sphere formed by rotating a semicircle of radius 2 units about x- axis. MATLAB CODE :- clc syms x f=input( 'Enter the function f(x): ' ); c=input( 'Enter the axis of rotation y = c (enter only c value): ' ); iL=input( 'Enter the integration limits: ' ); a=iL(1);b=iL(2); vol=pi*int((f-c)^2,a,b); disp([ 'Volume of solid of revolution is: ' ,char(vol)]); x1=linspace(a,b,20); y1=subs(f,x,x1);