0% found this document useful (0 votes)
162 views10 pages

Matlab 5b

This document contains the lab assignment submitted by Aditi Prashar for the calculus class MAT1011. It includes 4 questions asking the student to find vector fields, gradients, divergence, and curl of various vector functions, as well as calculating work done by vector forces along line segments and curves. Code is provided for the student to enter the vector functions and integrals to calculate the requested vector and multivariable calculus concepts.

Uploaded by

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

Matlab 5b

This document contains the lab assignment submitted by Aditi Prashar for the calculus class MAT1011. It includes 4 questions asking the student to find vector fields, gradients, divergence, and curl of various vector functions, as well as calculating work done by vector forces along line segments and curves. Code is provided for the student to enter the vector functions and integrals to calculate the requested vector and multivariable calculus concepts.

Uploaded by

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

[Date] MAT1011

CALCULAS FOE ENGINEERERS

Lab Assignment

Submitted To:
Padma R

Submitted by:
Aditi Prashar
20BCE0426
EXPERIMENT 5A
Ques 1. Draw the two dimensional vector field for the vector 2xi  3yj.

Code:

clear
clc
syms x y
f=input('Enter the 2D vector function in the form [f1,f2]:');
div(x,y)=divergence(f,[x,y]);
P(x,y)=f(1);Q(x,y)=f(2);
x=linspace(-4,4,20);y=x;
[X,Y]=meshgrid(x,y);
U=P(X,Y);V=Q(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(x,y)=[f1,f2]');

Input:

Output:
Ques2. Find the Gradient of the function f=x 2y3-4y.

Code:

clear
clc
syms x y
f=input('Enter the function f(x,y):');
grad=gradient(f,[x,y])
P(x,y)=grad(1);Q(x,y)=grad(2);
x=linspace(-2,2,10);y=x;
[X,Y]=meshgrid(x,y);
U=P(X,Y); V=Q(X,Y);
quiver(X,Y,U,V,1)
axis on
xlabel('x'); ylabel('y')
hold on
fcontour(f,[-2,2])

Input:

Output:
Ques3. Find the divergence of a vector field f [ xy,2x] .

Code:

clear
clc
syms x y
f=input('Enter the 2D vector function in the form [f1,f2]:');
div(x,y)=divergence(f,[x,y])
P(x,y)=f(1);Q(x,y)=f(2);
x=linspace(-4,4,20);y=x;
[X,Y]=meshgrid(x,y);
U=P(X,Y);V=Q(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(x,y)=[f1,f2]');

Input:

Output:
Ques4. Visualize the curl of a vector function f [yz,3zx,z]

Code:

clear
clc
syms x y z
f=input('Enter the 3D vector function in the form [f1,f2,f3]:');
P(x,y,z)=f(1);Q(x,y,z)=f(2);R(x,y,z)=f(3); %Components of vector f
crl=curl(f,[x,y,z]) %Calculating curl
C1(x,y,z)=crl(1);C2(x,y,z)=crl(2);C3(x,y,z)=crl(3);%Components of curl(f)
x=linspace(-4,4,10);y=x;z=x;
[X,Y,Z]=meshgrid(x,y,z);
U=P(X,Y,Z);V=Q(X,Y,Z);W=R(X,Y,Z);
CR1=C1(X,Y,Z);CR2=C2(X,Y,Z);CR3=C3(X,Y,Z);
figure;
subplot(1,2,1);
quiver3(X,Y,Z,U,V,W);
title('3-D view of vector field');
subplot(1,2,2);
quiver3(X,Y,Z,CR1,CR2,CR3);
title('3-D view of curl');

Input:

Output:
EXPERIMENT 5B
Ques 1. Find the work done for the force 𝐹⃗(x,y,z)= yz𝑖⃗ + xz 𝑗⃗ + (xy+2z) 𝑘⃗⃗ along the line segment from
(1,0,-2) to (4,6,3).

Code:

clc
clear all
syms x y z t
f=input('Enter the components of 3D vector function [u,v,w] ');
r=input('Enter x,y,z in parametric form');
I=input('Enter the limits of integration for t in the form [a,b]');
a=I(1);b=I(2);
dr=diff(r,t);
F=subs(f,{x,y,z},r);
Fdr=sum(F.*dr);
S=int(Fdr,t,a,b)
P(x,y,z)=f(1);Q(x,y,z)=f(2); R(x,y,z)=f(3);
x1=linspace(0,1,10); y1=x1; z1=x1;
[X,Y,Z] = meshgrid(x1,y1,z1);
U=P(X,Y,Z); V=Q(X,Y,Z); W=R(X,Y,Z);
quiver3(X,Y,Z,U,V,W,1.5)
hold on
t1=linspace(0,1,10);
x=subs(r(1),t1);y=subs(r(2),t1);z=subs(r(3),t1);
plot3(x,y,z,'r')

Input:
Output:
Ques 2. Find the work done for the force 𝐹⃗(x,y,)= x2 𝑖⃗ + y2 𝑗⃗ along the arc of the parabola y =2x2 from
(-1,2) to (2,8).

Code:

clc
clear all
syms x y t
f=input('Enter the components of 2D vector function [u,v] ');
r=input('Enter x,y in parametric form');
I=input('Enter the limits of integration for t in the form [a,b]');
a=I(1);b=I(2);
dr=diff(r,t);
F=subs(f,{x,y},r);
Fdr=sum(F.*dr);
S=int(Fdr,t,a,b)
P(x,y)=f(1);Q(x,y)=f(2);
x1=linspace(-2*pi,2*pi,10); y1=x1;
[X,Y] = meshgrid(x1,y1);
U=P(X,Y); V=Q(X,Y);
quiver(X,Y,U,V,1.5)
hold on
t1=linspace(0,2*pi);
x=subs(r(1),t1);y=subs(r(2),t1);
plot(x,y,'r')

Input:
Output:

You might also like