Line integral
§ Because
the line integral needs to be computed repeatedly, it is advisable to
encapsulate it within a function.
To create a function
·
The function should begin as
follows:
function [y1, ..., yN] = fun_name(x1,
..., xM)
·
This declares a function
named fun_name that accepts inputs x1, ..., xM and returns outputs y1, ..., yN.
The function should end with end.
·
Function definition should
be at the end of the main program.
·
To use the function, call it
from the main main program as many times as needed.
%%%%%%%%%%%%%%%% Main
Program %%%%%%%%%%%%%%%%%%
clc
clear
syms x y
LInt=0;
%Get the number of sub
path in the curve C
n=input("How
many subcurves are ther in the curve C? :")
%Calculate the line
integral along each path
for i=1:n
line(i)=LineIntegral(x,y);
LInt =vpa(LInt +line(i))
end
%%%%%%%%%%%%%%%% Main
Program ends %%%%%%%%%%%%%%%%%%
%Define function for Line
integral
function line
= LineIntegral(x,y)
option=input("1:
y=f(x)\n2: x=g(y)\n")
switch option
case 1
y=input("Enter the function f(x):
\n")
r=[x y];
F=input("Enter the vector function
F(x,y)=[F1 F2]: F(x,y)")
dr=diff(r,x);
integrand1=dot(F,dr);
xL=input("Enter the lower limit of
x:");
xU=input("Enter the Upper limit of
x:");
line=int(integrand1,x,xL,xU)
case 2
x=input("Enter the function g(y):
\n")
r=[x y];
F=input("Enter the vector function
F(x,y)=[F1 F2]: F(x,y)")
dr=diff(r,y);
integrand1=dot(F,dr);
yL=input("Enter the lower limit of
y:");
yU=input("Enter the Upper limit of
y:");
line=int(integrand1,y,yL,yU)
otherwise
fprintf("Give the proper input")
end
end
%%%%%%%%%%%%%%%% Line
Integral definition ends %%%%%%%%%%%%%%%%%%
Example 1
How many subcurves are there in the curve C?
:1
n = 1
1: y=f(x)
2: x=g(y)
1
option = 1
Enter the function f(x):
2*x^2
y =
2*x^2
Enter the vector function F(x,y)=[F1 F2]:
F(x,y)=[3*x*y -y^2]
F =
[6*x^3, -4*x^4]
Enter the lower limit of x:0
Enter the Upper limit of x:1
line =
-7/6
LInt =
-1.1666666666666666666666666666667
Line
integral using the parametric form
clear
clc
syms x y z
t
x=input("Enter
x(t):"); % If x ,y, z is a function of
‘t’
y=input("Enter
y(t):");
z=input("Enter
z(t):");
r=[x y z];
F=input("Enter
the vector function F(x,y,z):")
dr=diff(r,t);
integrand1=dot(F,dr);
tl=input("Enter
the lower limit of t:");
tu=input("Enter
the Upper limit of t:");
line=int(integrand1,t,tl,tu)
Example 1
$$\text{Evaluate }\int F\cdot dr$$ $$\text{where c is the curve given by }x=2t^2, y=t, z=t^3$$
$$\text{from (0,0,0) to (2,1,1) and } F=(2y+3)\hat{i}+xz\hat{j}+(yz-x)\hat{k}.$$
Output
Enter
x(t):2*t^2
Enter
y(t):t
Enter
z(t):t^3
Enter
the vector function F(x,y,z):[2*y+3 x*z yz-x]
Enter
the vector function F(x,y,z):[2*y+3 x*z y*z-x]
F
=
[3
+ 2*t, 2*t^5, - 2*t^2 + t^4]
Enter
the Lower limit of t:0
Enter
the Upper limit of t:1
line
=
288/35
No comments:
Post a Comment