Beruflich Dokumente
Kultur Dokumente
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 ∫ ⃗𝑭 . 𝒅𝒓
𝒂
⃗ = ∫ [𝑭(𝒓(𝒕)). 𝒓′ (𝒕)𝒅𝒕]
𝒂
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)});
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.
𝒃 𝒃
∫𝒂 ⃗𝒇 . 𝒅𝒓
⃗ = ∫𝒂 [𝒇(𝒓(𝒕)). 𝒓′ (𝒕)𝒅𝒕]
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
Exercise: