0% found this document useful (0 votes)
20 views8 pages

With Out Name

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views8 pages

With Out Name

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Problem 1:

Matlab code:
clc
clear all
% Set up the region
x = linspace(0, 3, 100);
y = linspace(0, sqrt(2), 100);
[X, Y] = meshgrid(x, y);

% Define the two surfaces


z1 = X.^2 + 3*Y.^2;
z2 = 8 - X.^2 - Y.^2;

% Find the intersection curve


[Xint, Yint] = meshgrid(linspace(0, 3, 100));
Zint = Xint.^2 + 3*Yint.^2;

% Plot the surfaces and intersection curve


figure;
surf(X, Y, z1, 'FaceAlpha', 0.7)
hold on;
surf(X, Y, z2, 'FaceAlpha', 0.7)
plot3(Xint(:), Yint(:), Zint(:), 'k', 'LineWidth', 2)
xlabel('x'); ylabel('y'); zlabel('z');
title('Region Bounded by the Surfaces');

% Calculate the volume using numerical integration


[X, Y] = meshgrid(linspace(0, 3, 100), linspace(0, sqrt(2), 100));
volume = trapz(trapz(z2(X >= 3*Y) - z1(X >= 3*Y)));
disp(['Volume of the region: ', num2str(volume)])

Output:
problem 2:

Matlab code:
% Define the surface function
f = @(x, y, z) x.^2.*y + 2*x.*z.^2 - 8;

% Point on the surface


p = [1 0 2];

% (i) Normal vector


grad_f = @(x, y, z) [2*x*y + 2*z^2, x^2, 4*x*z];
normal = grad_f(p(1), p(2), p(3));
disp(['Normal vector at (1,0,2): ', num2str(normal)])

% (ii) Directional derivative


v = [1 -3 6];
v_norm = v / norm(v);
directional_derivative = dot(grad_f(p(1), p(2), p(3)), v_norm);
disp(['Directional derivative at (1,0,2) in the direction of v: ',
num2str(directional_derivative)])

Output:
Normal vector at (1,0,2): 8 1 8
Directional derivative at (1,0,2) in the direction of v: 7.8144
>>
problem 3:

Matlab code:
clc
clear all
% Define the vector function F
syms x y z
F = [x+y, y-z, z];

% Define the vector function F


syms x y z
F = [x+y, y-z, z];

% Apply gradient to each component of F


gradF = [diff(F(1), x), diff(F(1), y), diff(F(1), z); ...
diff(F(2), x), diff(F(2), y), diff(F(2), z); ...
diff(F(3), x), diff(F(3), y), diff(F(3), z)];

% Display the result


disp('Gradient of F (∇F):');
disp(gradF);

% (ii) Curl of F (∇xF)


curlF = curl(F, [x, y, z]);

% (iii) Cross product of x and curlF (x × (∇xF))


cross_product = cross([x, y, z], curlF);

% (iv) Gradient of the divergence of F (∇(∇·F))


divF = divergence(F, [x, y, z]);
grad_divF = gradient(divF, [x, y, z]);

% Display the results


disp('(i) Gradient of F (∇F):');
disp(gradF);

disp('(ii) Curl of F (∇xF):');


disp(curlF);

disp('(iii) Cross product of x and curlF (x × (∇xF)):');


disp(cross_product);

disp('(iv) Gradient of the divergence of F (∇(∇·F)):');


disp(grad_divF);
Output:
Gradient of F (∇F):
[1, 1, 0]
[0, 1, -1]
[0, 0, 1]

(i) Gradient of F (∇F):


[1, 1, 0]
[0, 1, -1]
[0, 0, 1]

(ii) Curl of F (∇xF):


1
0
-1

(iii) Cross product of x and curlF (x × (∇xF)):


[-y, x + z, -y]

(iv) Gradient of the divergence of F (∇(∇·F)):


0
0
0

problem 4:

Matlab code:

% (4) Evaluate the line integral


t = linspace(0, 2*pi, 100); % Discretize the interval [0, 2pi]
r = [2*cos(t); 2*sin(t); 2*ones(size(t))]; % Vector function r(t)
F = [exp(r(1,:)); 2*r(2,:); -ones(size(t))]; % Vector field F
dr = diff(r, 1, 2); % Differential of r(t)
line_integral = sum(F(:, 1:end-1) .* dr, 1); % Line integral approximation

disp(['Line integral: ', num2str(line_integral)]);

Output:
Line integral: -0.029753 -0.05673 -0.082345 -0.10555 -0.12546
-0.1414 -0.15295 -0.15995 -0.16253 -0.16105 -0.1561
-0.14842 -0.13888 -0.12838 -0.11782 -0.10804 -0.099802
-0.093721 -0.09027 -0.089761 -0.092344 -0.098017 -0.10663
-0.11793 -0.13152 -0.14696 -0.16373 -0.18128 -0.19903
-0.2164 -0.23284 -0.24782 -0.26084 -0.27146 -0.27931
-0.28406 -0.28547 -0.28338 -0.27767 -0.26832 -0.25538
-0.23896 -0.21926 -0.1965 -0.171 -0.14311 -0.11323
-0.081793 -0.049257 -0.016107 0.017165 0.050061 0.082093
0.11279 0.14169 0.16839 0.1925 0.2137 0.23171
0.2463 0.25733 0.2647 0.2684 0.2685 0.26511 0.25845
0.24878 0.23645 0.22185 0.20545 0.18774 0.16926
0.15058 0.13227 0.11488 0.098958 0.084994 0.073413
0.064552 0.058641 0.055782 0.055937 0.058912 0.064355
0.071763 0.080489 0.089769 0.098758 0.10656 0.11231
0.11519 0.11451 0.10975 0.10063 0.087103 0.069408
0.048042 0.023743 -0.0025472
>>
problem 5:

Matlab code:

clc
clear all

% (5) Plot vector fields


% (i)
t = linspace(0, 2*pi, 50);
r = [cos(t); sin(t); t];
quiver3(r(1,:), r(2,:), r(3,:), cos(t), sin(t), ones(size(t)), 'LineWidth',
1.5);
xlabel('x'); ylabel('y'); zlabel('z'); title('Vector Field r(t)');

% (ii)
[x, y] = meshgrid(-3:0.5:3, -3:0.5:3);
u = -y;
v = x;
quiver(x, y, u, v, 'LineWidth', 1.5);
axis([-3 3 -3 3]);
xlabel('x'); ylabel('y'); title('Vector Field F(x,y)');

Output:
problem 6:
Matlab code:
% Define the limits for the polar coordinates
r_min = 0;
r_max = 1;
theta_min = 0;
theta_max = pi/2;

% Define the integrand in polar coordinates


integrand = @(r, theta) r.^3 .* cos(theta).^2 .* sin(theta);

% Evaluate the integral using symbolic integration


syms r theta;
integral_polar = int(int(integrand(r, theta), r, r_min, r_max), theta,
theta_min, theta_max);

% Display the result


disp(integral_polar)

Output:
1/12
problem 7:

Matlab code:
% De ne the function f(x,y)
f = @(x,y) x.^2.*y - y.^3;

% De ne the gradient of f
grad_f = @(x,y) [2*x*y; x.^2 - 3*y.^2];

% Create a grid of points for plotting


[x,y] = meshgrid(-2:0.2:2, -2:0.2:2);

% Evaluate the gradient at each point on the grid


u = grad_f(x,y);

% Reshape u for quiver function


u1 = u(1,:,:);
u2 = u(2,:,:);

% Plot the gradient vector eld


quiver(x(:), y(:), u1(:), u2(:));

% Plot some level curves of f


hold on;
contour(x,y,f(x,y),[-10:2:10]);
hold o ;

% Add labels and title


xlabel('x');
ylabel('y');
title('Gradient Vector Field and Level Curves of f(x,y) = x^2*y - y^3’);

Output:
fi
fi
ff
fi
problem 8:

Matlab code:
% Define the vector field components
syms x y z % Declare symbolic variables x, y, z
P = y^2*z^3;
Q = 2*x*y*z^3;
R = 3*x*y^2*z^2;

% Check for conservative field (curl F = 0)


curlF = [diff(R,y) - diff(Q,z); diff(P,z) - diff(R,x); diff(Q,x) - diff(P,y)];

if all(curlF(:) == 0)
disp('The vector field is conservative.');

% Find the potential function f


syms f(x,y,z) % Declare symbolic function f(x,y,z)
syms g(y,z) % Declare symbolic function g(y,z)
syms h(z) % Declare symbolic function h(z)

% Integrate P with respect to x


f = int(P, x) + g(y,z);

% Differentiate f with respect to y and equate it to Q


diff(f, y) == Q;

% Solve for g(y,z)


g = int(solve(diff(f, y) == Q), y) + h(z);

% Substitute g(y,z) back into f


f = subs(f, g);

% Differentiate f with respect to z and equate it to R


diff(f, z) == R;

% Solve for h(z)


h = int(solve(diff(f, z) == R), z);

% Substitute h(z) back into f


f = subs(f, h);

% Display the potential function


disp('The potential function f is:');
pretty(f)

else
disp('The vector field is not conservative.');
end

Output:
The vector field is conservative.

You might also like