Project Basha
Project Basha
Project Basha
clear
c Ic
syms x Y
Enter the function f (x, y) : t)
grad=gradient (f, [x, y) )
P (x, y) =grad (1) ; Q (x, y) —grad (2) ;
x=linspace (—2, 2, IO) ; y=x;
[X, Y) =meshgrid (x, y) ;
quiver (X, Y, U, V 1)
axis on
x label
ylabel ( 'y ' )
hold on
fcontour (f, [-2,2])
Example 2: Find the divergence of the vector field F = xy i + x j and visualize it.
clear
CIC
syms x Y
f=input ( 'Enter the 2D vector function in the form [f 1, f 2] : ' )
div (x, y) —divergence (f, [x, y) )
x=linspace (—4, 4, 20) ; y—x;
[X, Y) =meshgrid (x, y) ;
figure
pcolor (X, Y, div (X, Y)) ;
shading interp
hold on;
quiver (X, Y, U, V, 1)
axis on
hold off;
title ('Vector field of F t);
Intput:
Enter the 2D vector function in the form [f I, f2) :[x*yA2, xA2)
Example. 1 To find
— dydx.
syms x y z
int (int( (x+y) /4,y,x/2,x) , x, 1, 2)
vicwS01id(z, (x+Y) / 4, y, x/ 2, x, x, 1, 2)
Example 1.
The volume of the solid generated by the revolving the curve y x about the line y 1 from x 1 to
x 4 is given by the following code:
clear
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);
surf(Z,Y+yr,X)
hold on;
plot([a b],[yr yr],'-r','LineWidth',2); % Plotting the line y=yr
view(22,11);
xlabel('X-axis');ylabel('Y-axis');zlabel('Z-axis');
Example 1. Find the volume of the region D enclosed by the surfaces z = x ^ 2 + 3y ^ 2 andz = 8 - x ^ 2 - y ^ 2
clear
clc
syms xy 2
xa = - 2z
xb=2;
ya-sqrt (2-x^2/2);yb = sqrt(2 - x ^ 2 / 2)
za=x^2+3+y^2;
zb = 8 - x ^ 2 - y ^ 2 * z
I=int (int (int (1+0*z, z, za, zb), y, ya, yb), x,xa, xb)
viewSolid (z, za, zb, y, ya, yb, x, xa, xb)
Output
I =8*pi*2^(1/2)
Example 3. Find the volume of the region in the first octant bounded by the coordinate
planes, the plane y=1-x, and the surface=cos(x/2), 0≤x≤1.
The limits of integration are z=0 to cos(x/2), y=0 to 1-x, x=0 to 1.
clear
clc
syms xyz real
xa-0:
xb=1; ya-0+0+x/
yb-1-x/ za-0*x+0*y:
zb-cos (pix/2)+0+y: I-int (int (int (1+0z, z, za, zb),y,ya, yb), x, xa, xb) viewSolid (z,za, zb, y, ya, yb, x, xa, xb)
Output.
4/pi 2
Example 2. Find the volume of the region cut from the cylinder x ^ 2 + y ^ 2 = 4 by the plane
z = 0 and the plane x + z = 3
The limits of integration are tau = 0t 3-x, x = - sqrt(4 - y) to sqrt(4 - y) y = - 2 to 2.
clear
clc
syms xyz
ya = - 2
yb-2;
xa-sqrt (4-y^2);
xb = sqrt(4 - y ^ 2) ;
: a =0+0^ * x+0^ * v:
zb= 3 - x -0^ * yi
T = integrate i di int (int (1+0*z, z, za, zb), x, xa, xb), y, ya, yb)
viewSolidone z, za, zb, x, xa, xb y, ya, yb)
Output
T=
12pj