Sie sind auf Seite 1von 4

Department of Mathematics

School of Advanced Sciences


MAT 1011 – Calculus for Engineers (MATLAB)
Experiment 5–B
Line integral and work done

Aim:
 To write the MATLAB codes to find the work done by the force ⃗𝑭and visualize the force
field with the path.

Mathematical form:

 Let the given function be ⃗𝑭=F1(x,y,z)𝒊 +F2(x,y,z)𝒋 +F3(x,y,z)𝒌 ⃗ . Let the parametric form be
𝒃 𝒃
r = [ r1 (t) r2 (t) r3 (t) ] with a≤t≤ 𝒃 . Then ∫ ⃗𝑭 . 𝒅𝒓
𝒂
⃗ = ∫ [𝑭(𝒓(𝒕)). 𝒓′ (𝒕)𝒅𝒕]
𝒂

MATLAB Syntax used:

inline(expr) Constructs an inline function object from the MATLAB


expression contained in the string expr.
vectorize(fun) Inserts a . before any ^, * or / in s. The result is a character
string
quiver(x,y,u,v) Displays velocity vectors as arrows with components (u,v) at
the points (x,y)
quiver3(x,y,z,u,v,w) Plots vectors with components (u,v,w) at the points (x,y,z))
eval(expression) Executes expression, a string containing any valid MATLAB
expression.

Finding the line integral for a function be ⃗𝒇=u(x,y)𝒊 +v(x,y)𝒋, with x  x(t ) and y  y(t ) .
𝒃 𝒃
⃗ . 𝒅𝒓
∫𝒂 𝒇 ⃗ = ∫𝒂 [𝒇(𝒓(𝒕)). 𝒓′ (𝒕)𝒅𝒕]

MATLAB Code:
clc
clear all
syms x y t
% Code for 2D vector function
f=input('Enter the components of 2D vector function [u,v] ');
T=input('Enter x and y in parametric form ');
L=input('Enter the limits of integration for t in the form [a,b]');
a=L(1);b=L(2);
r=[x y]; % Position vector xi+yj
r1=subs(r,{x,y},{T(1),T(2)});
dr1=diff(r1,t);
f1=subs(f,{x,y},{T(1),T(2)});

Department of Mathematics, Vellore Institute of Technology, Vellore. Page 1


fdr=sum(f1.*dr1);
I=int(fdr,t,a,b);
disp(I)
P = inline(vectorize(f(1)), 'x', 'y');
Q = inline(vectorize(f(2)), 'x', 'y');
x = linspace(-2*pi,2*pi, 10); y = x; %The values will be different
from one problem to another
[X,Y] = meshgrid(x,y);
U = P(X,Y);V = Q(X,Y);
quiver(X,Y,U,V,1.5)
hold on
t = linspace(0,2*pi);
x1=eval(vectorize(r1(1)));
y1=eval(vectorize(r1(2)));
plot(x1,y1,'r')
axis equal

Example 1:
Evaluate ∫𝑐 𝐹. 𝑑𝑟 along the given curve C. F: xy2𝑖 +x2y𝑗 r: [t+sin(πt/2) t+cos(πt/2)] 0≤t≤1

Input:
Enter the components of 2D vector function [u,v] [x*y^2 x^2*y]
Enter x and y in parametric form [t+sin((pi*t)/2) t+sin((pi*t)/2)]
Enter the limits of integration for t in the form [a,b][0,1]

Output:
8

Inference:
The arrows represents the vector field and the curve(red) represents the path C.

Department of Mathematics, Vellore Institute of Technology, Vellore. Page 2


⃗ , with x  x(t ) , y  y(t )
Finding the line integral for a function be ⃗𝒇=u(x,y,z)𝒊 +v(x,y,z)𝒋+ w(x,y,z)𝒌
and z  z (t )

𝒃 𝒃
∫𝒂 ⃗𝒇 . 𝒅𝒓
⃗ = ∫𝒂 [𝒇(𝒓(𝒕)). 𝒓′ (𝒕)𝒅𝒕]

MATLAB Code:
clc
clear all
syms x y z t
f =input('Enter the components of 3D vector function [u,v,w] ');
T =input('Enter x,y,z in parametric form');
r=[x y z];
L=input('Enter the limits of integration for t in the form [a,b]');
a=L(1);b=L(2);
r1=subs(r,{x,y,z},{T(1),T(2),T(3)});
dr1=diff(r1,t);
f1=subs(f,{x,y,z},{T(1),T(2),T(3)});
fdr=sum(f1.*dr1);
I=int(fdr,t,a,b);
disp(I)
P = inline(vectorize(f(1)), 'x', 'y','z');
Q = inline(vectorize(f(2)), 'x', 'y','z');
R = inline(vectorize(f(3)), 'x', 'y','z');
x=linspace(0,1,10); y=x; z=x; % The values will be different from one
problem to another
[X,Y,Z] = meshgrid(x,y,z);
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
t = linspace(0,1,10);
x1=eval(vectorize(r1(1)));
y1=eval(vectorize(r1(2)));
z1=eval(vectorize(r1(3)));
plot3(x1,y1,z1,'r')

Example 2:
⃗ r: [t t2 t3] 0≤t≤1
Evaluate ∫𝑐 𝐹. 𝑑𝑟 along the given curve C. F: xy𝑖+yz𝑗+zx𝑘

Input:
Enter the components of 3D vector function [u,v,w] [x*y y*z z*x]
Enter x,y,z in parametric form [t t^2 t^3]
Enter the limits of integration for t in the form [a,b] [0,1]

Output:
27/28

Department of Mathematics, Vellore Institute of Technology, Vellore. Page 3


Inference:
The arrows represent the vector field and the red line represents the path C.

Exercise:

1) ⃗ along the line segment


Find the work done for the force 𝐹 (x,y,z)= yz𝑖 + xz 𝑗 + (xy+2z) 𝑘
from (1,0,-2) to (4,6,3).
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).

Department of Mathematics, Vellore Institute of Technology, Vellore. Page 4

Das könnte Ihnen auch gefallen