(123doc) Calculus 2 Assignment Report

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 44

VIET NAM NATIONAL UNIVERSITY, HO CHI MINH CITY HO CHI

MINH CITY UNIVERSITY OF TECHNOLOGY

CALCULUS 2
REPORT
Instructor: Đậu Thế Phiệt

Class: CC01 – Group 02

Student name ID
Huỳnh Dương Gia Bả o 2252063
Nguyễn Khá nh Duy 2252117
Phù ng Nhậ t Huy 2252261
Tạ Anh Huy 2211272
Đỗ Quang Sinh 2252715
Lê Huỳnh Phú c 2252634
Trầ n Tấ n Tà i 2252728
Võ Minh Thă ng 2252762
2|Page
Contents
A. Introduction ..........................................................................................................3

B. Problem:

I. Problem 1..........................................................................................4

II. Problem 2 .......................................................................................13

III. Problem 3 ........................................................................................21

C. Conclusion ....................................................................................................31

3|Page
Ho Chi Minh City University of Technology
Faculty of Applied Science

A. INTRODUCTION

In this project, there are three


problems from the Calculus 2 that
are relevant to our theoretical
lessons. Based on what we have
learned and understood, we will
illustrate how to solve the issues
and explain all underlying theories
using our knowledge of Calculus 2.

4|Page
Ho Chi Minh City University of Technology
Faculty of Applied Science

B. PROBLEMS
I. Problem 1
Let z=f ( x ) =x2 +2 y 2 +3 x y 3− y3

(a) Draw the graph of the function.

(b) Draw the contour plot of the function. Point out the local extreme and the saddle
point on that figure.

(c) Find the exact local extreme and saddle point (using calculus technique).

Theory:
We all know that the main uses of ordinary derivatives are to find maximum and minimum
values (extreme values). Similar with multivariable functions, we can use partial derivatives
to do the same thing.
Suppose we have a two-variable function f that is continuous on the interval (a ,b) and it is said
that:
A function f of two variables has a local maximum at (a ,b) if :

f (x , y )≤ f (a , b)

when(x , y)is near (a ,b)

This means that f (x , y )≤ f (a , b) for all points (x , y ) in some disk with center (a ,b).
The number f (a , b) is called a local maximum value. If f (x , y )≥ f (a , b) when (x , y ) is
near (a ,b), then f has a local minimum at (a ,b) and f (a , b) is a local minimum value.
If the inequalities in the above definition hold for all points (x, y) in the domain of f then f
has an absolute maximum or local minimum at (a, b).
Therefore, If f has a local maximum or minimum at (a, b) and the first-order partial
derivatives of f exist at that point. And then

{f x (a , b )=0
f y ( a ,b )=0

But in some problems, there is a point called saddle point which located at the origin. Thus,
we have another tool called Second Derivatives Test to determine which points are
minimum, maximum and saddle.
Assume that the second partial derivatives are continuous on a disk with center (a, b), and
suppose:

5|Page
Ho Chi Minh City University of Technology
Faculty of Applied Science

{f x ( a , b )=0
f y ( a , b )=0

Let:
2
D ( a , b ) =f xx ( a , b ) . f yy ( a , b )−[ f xy ( a , b ) ]

If {fD>0>0 , then f (a , b) is the local minimum.


xx

If {fD>0<0 , then
xx
f ( a , b ) is the local maximum.

If D<0 , then f (a , b) is not a local extrema, the point (a ,b) is called a saddle point of f

Note: If D=0, the test tells no information. f could have a local maximum or local
minimum at (a ,b), or (a ,b) could be a saddle point of f .

Finding the local extreme values of the function f (x , y ):

 Identifying critical points for the given function f ( x , y ) .

– Find the partial derivatives with respect to x and to y .


– Set each partial derivative equal to zero.
– Solve the system of equations to get critical points (x0, y0).
 Consider D ¿).

– Find all second derivatives of f (x 0 , y 0).


2
– Identify by the Second Derivative Test D ( a , b ) =f xx ( a , b ) . f yy (a , b)−[ f xy ( a , b ) ]

Hand-writing solution:
Find the local extreme values of the function f (x , y )=x 2 +2 y 2+3 x y 3− y 3
- Firstly, we have to determine critical points for the given function f (x , y ) by
finding the partial derivatives with respect to x and to y and set each
partial derivative equal to zero.

{
' 3
f x =2 x +3 y
f y =4 y+ 9 x y 2−3 y 2
'

6|Page
Ho Chi Minh City University of Technology
Faculty of Applied Science
- We then have the system of equations:

{
3
2 x+ 3 y =0(1)
2 2
4 y + 9 x y −3 y =0 (2)

- Solve the equation (1) for x :

−3 3
x= y (4)
2

- Substitute that value to the equation (2):

4 y +9 ( −32 y ) y −3 y =0
3 2 2

- Simplify the above equation:

y ( −272 y −3 y + 4)=0
4

- Solve the equation for y and substitute the value to the equation (4):

y=0⇒ x=0

y=0.629⇒ x=−0.373

y=−0.833 ⇒ x=0.867

- Thus, we have three critical points: (0,0) , (-0.373,0.629) , (0.867,-0.833)

- Next step is to consider D(x 0 , y 0) by finding all second derivatives of


f ( x 0 , y 0 ) and identify by the Second Derivative Test
2
D ( x 0 , y 0 ) =f xx ( x 0 , y 0 ) −[ f xy ( x 0 , y 0 ) ]

- We have:

{
f xx =2
2
f xy =9 y
f yy =4 +18 xy−6 y

- Therefore:
4
D ( x 0 , y 0 ) =−81 y +36 xy−12 y +8 (5)

7|Page
Ho Chi Minh City University of Technology
Faculty of Applied Science

- Then, we substitute 3 critical points into equation (5) in turn.

 At (0,0):

– D ( 0 , 0 )=8 >0

– f yy ( 0 , 0 )=2>0

⇒ f (0 , 0) is a local minimum.

 At (-0.373,0.629):

– D (−0.373 , 0.629 )=−20.678<0

⇒ (−0.373 , 0.629) is a saddle point of f

MATLAB code:

% calculation

syms x y z

z = x .^2 + 2* y .^2 + 3* x .* y .^3 - y .^3;

% differentiate z

fx = diff (z ,x ,1) ; fy = diff (z ,y ,1) ;

fxx = diff (z ,x ,2) ; fyy = diff (z ,y ,2) ;

fxy = diff ( fx ,y ,1) ;

% create a system equation

eqns = [ fx == 0 , fy == 0];

% define the variables for system equation

vars = [ x y ];

% solve the system equation

[ solx , soly ] = vpasolve ( eqns , vars ) ;

% only choose the real value

solx_real = solx ( imag ( solx ) ==0) ;

8|Page
Ho Chi Minh City University of Technology
Faculty of Applied Science
soly_real = soly ( imag ( solx ) ==0) ;

% display section

disp ([ 'z = f(x,y) = ', char ( z ) ])

disp ([ 'fx = ', char ( fx ) ])

disp ([ 'fy = ', char ( fy ) ])

disp ([ 'fxx = ', char ( fxx ) ])

disp ([ 'fyy = ', char ( fyy ) ])

disp ([ 'fxy = ', char ( fxy ) ])

%c

for n =1: length ( solx_real )

fxx_val = subs ( fxx ,[ x ,y ] ,[ solx_real ( n ) , soly_real ( n ) ]) ;

% calculate fxx , fyy , fxy values

fyy_val = subs ( fyy ,[ x ,y ] ,[ solx_real ( n ) , soly_real ( n ) ]) ;

fxy_val = subs ( fxy ,[ x ,y ] ,[ solx_real ( n ) , soly_real ( n ) ]) ;

D = fxx_val * fyy_val - fxy_val * fxy_val ;

fprintf ('\ nFor point (%s ,%s)\n ', solx_real ( n ) , soly_real ( n ) )

if D > 0

fprintf ('D = fxx *fyy - fxy ^2 = %s\n ',D )

fprintf ('So D > 0\n')

fprintf ('Therefore point (%s ,%s) is local extreme \n ', solx_real ( n) ,


soly_real ( n ) )

if fxx_val > 0

fprintf ('And fxx = %s\n ', fxx_val )

fprintf ('So fxx > 0\n')

9|Page
Ho Chi Minh City University of Technology
Faculty of Applied Science
fprintf ('Therefore this is a local minimum point \n ')

else

fprintf ('And fxx = %s\n ', fxx_val )

fprintf ('So fxx < 0\n')

fprintf ('Therefore this is a local maximum point \n ')

end

else if D < 0

fprintf ('D = fxx*fyy - fxy ^2 = %s\n ',D )

fprintf ('So D < 0\n')

fprintf ('Therefore point (%s ,%s) is a saddle point \n ', solx_real ( n ) , soly_real ( n )
)

else

fprintf ('D = fxx*fyy - fxy ^2 = %s\n ',D )

fprintf ('So conclusion for point (%s ,%s) \n ', solx_real ( n ) , soly_real ( n ) )

end

end

Code explanation:

 syms x y z; - declares symbolic variables x, y, and z to be used.

 z = x.∧ 2 + 2*y.∧ 2 + 3*x.*y.∧ 3 - y.∧ 3; - defines a symbolic expression for z as a


function of x and y.

 fx = diff(z,x,1); - calculates the first partial derivative of z with respect to x and


assigns it to the variable fx. Similar for fy, fxx, fyy and fxy.

 eqns = [ fx == 0, fy == 0]; - creates a system of equations eqns that must be solved


simulta

 neously, which are the first-order partial derivative equations set to zero.

10 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science
 vars = [x y]; - defines the variables to be solved for as x and y.

 [solx, soly] = vpasolve(eqns, vars); - solves the system of equations eqns for the
variables vars and returns the solutions in the vectors solx and soly.

 solx_real = solx(imag(solx)==0); - extracts the real parts of the solutions for solx
and assigns them to solx_real.

 disp([’z = f(x,y) = ’, char(z)]); - displays the symbolic expression for z as a function


of x and y.

 for n=1:length(solx_real) - starts a loop over the number of real solutions found.

 fxx_val = subs(fxx,[x,y],[solx_real(n),soly_real(n)]); - substitutes the values of


solx_real(n) and soly_real(n) into the symbolic expression for fxx and assigns the
resulting value to fxx_val.

 vpasolve(); - function is used to solve the system of equations eqns for the variables
vars, which are x and y in this case.

 fprintf() - displays the results of the calculations.

11 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science
Graph of the function z=f ( x ) =x 4−2 x 2− y 3 +3 y

syms x y z
[x , y ] = meshgrid ( -1:0.05:1 , -1:0.05:1) ;
z = x .^2 + 2* y .^2 + 3* x .* y .^3 - y .^3;
% plot 2 figure in 1 window
tiledlayout (2 ,1) ;

%a
nexttile
surf (x ,y ,z , 'edgecolor ', 'none ') ;
colormap hot ; %the higher value , the hotter color

xlabel ('x') ;
ylabel ('y') ;
zlabel ('z') ;
title ('GRAPH OF THE FUNCTION ')
pbaspect ([1 ,1 ,1])
%b
nexttile
contour (x ,y ,z ,200)
hold on
for n =1: length ( solx_real )
plot ( solx_real ( n ) , soly_real ( n ) , '*')
end
xlabel ('x') ;
ylabel ('y') ;
title ({ 'CONTOUR PLOT THE FUNCTION , ','LOCAL EXTREME AND SADDLE POINT ' })
pbaspect ([1 ,1 ,1])

12 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

The contour plot the function z=f ( x ) =x 4−2 x 2− y 3 +3 y along with the local
extreme and saddle point

Code explanation:

 meshgrid() - generate a grid of x and y values to plot the surface and contour plots of the
function.

 tiledlayout() - create a tiled layout for plotting multiple figures in one window

 nexttile() - specify the location of the next plot in the tiled layout.

 surf() - create a surface plot of the function.

 colormap() - set the colormap for the surface plot.

 title() - add title to the plot

 contour() - create a contour plot of the function. It takes x, y, and z matrices as input, and
creates contour lines at different function values.

 hold on - allow multiple plots to be overlaid on top of each other.

 for loop - plot the location of the local extreme and saddle points on the contour plot.

 pbaspect() - set the aspect ratio of the plot.

13 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

II. Problem 2
Find the maximum and minimum values of z=2 x 2−2 xy + y 3 subject to the single constraint
x2 +y2 = 4.

(a) Using Lagrange multiplier method.

(b) Using contour plot (Draw the contour plot of the function and the constraint curve in the same
figure).

Theory:
To find the maximum and minimum value of f ( x , y )=2 x 2−2 xy + y 3 subject to the single
constraint g(x , y)= x2 + y 2=4 , we need to use the Lagrange multiplier method.

Lagrange multiplier method is a technique for finding maximum or minimum values of some
multivariable function f (x , y , z , ...) subject to a constraint of the form g(x , y , z ,...).

For example, a function of 2 variables can be used to explain the method. We get started by
finding the extreme values of f (x , y ) subject to a constraint g(x , y). In other words, we find the
points satisfying the condition that points (x , y ) lie on the level curve g(x , y)=k . The figure below
shows this curve together with several level curves of f (x , y ). These have the equations
f (x , y )=c where c ∈{7 ,8 ,9 , 10 , 11}.

14 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

The graph illustrates that the maximum value occupied at the point where f (x , y )=10 intersecting
g(x , y)=k . Analyzing the graph, we can easily see the fact that the maximum value appears when
those 2 functions touch each other and they have the same tangent line. Thus the normal lines at
the point of intersection (x0, y0) are identical. So the gradient vectors are parallel; Therefore,
∇ f (x 0 , y 0)=λg(x 0 , y 0)
where λ is a scalar.
For some scalar λ. The scalar parameter is called a Lagrange multiplier. The procedure based on
the above equation is as follows. We have from the chain rule,

df ( x , y ) ∂ f ( x , y ) ∂f (x , y) dg ( x , y ) ∂ g ( x , y ) ∂g(x , y)
= dx+ dy , = dx + dy
dxdy ∂x ∂y dxdy ∂x ∂y

Multiplying the second equation by λ and then add to first equation yield:

( ∂f (x , y ) ∂g(x , y)
∂x
+
∂x ) (
dx+
∂f (x , y) ∂g(x , y )
∂y
+
∂y
dy=0 )
Then we can rewrite the expression as the vector equation:

∇ f (x 0 , y 0)=λg(x 0 , y 0)

Thus, the maximum and minimum values of f (x , y ) subject to the constraint g(x 0 , y 0)=0can be
found by solving the following set of equations.

{
∂ f (x , y ) ∂ g ( x , y )
+ =0
∂x ∂x
∂ f (x , y ) ∂ g ( x , y )
+ =0
∂y ∂y
g ( x , y ) =0

The Lagrange multiplier method allows us to find the values of the variables that optimize the
objective function subject to the given constraints. This technique is widely used in various fields of
mathematics, physics, and engineering, particularly in optimization problems involving constraints.

14 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

Solving Problem using Lagrange multiplier method:

2 3
Let f ( x , y )=z=2 x −2 xy+ y and g( x , y)= x2 + y 2 – 4

Therefore, we obtain a system of equations:

{
4 x−2 y +2 λx=0(1)
−2 y+ 3 y 2 +2 λy=0 (2)
x 2+ y2 −4=0(3)

Solve the equation (1) for x , we get:


y
x=
2+ λ

Substitute x in the equation (2):


2 2y
3 y +2 λy− =0(4)
2+ λ
Then we substitute x into the equation (3) and solve for y :
2
y 2
2
+ y =4
( 2+ λ )

2 4
⟹y =
1
1+
( 2+ λ )2
2
⟹ y=±

−2
√ 1+
1
( 2+ λ )
2

y=
Plug
√ 1+
1 to equation (4) then we obtain:
( 2+ λ )
2

4 −2 −4
3 +2λ − =0

√ √
1
( 2+1 λ )
2
1+ 1
1+ ( 2+ λ ) 1+
( 2+ λ )2 ( 2+ λ )
2

15 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

Then we obtain 2 values of λ :


λ=3.13935∧ λ=−2.31197

2
y=
With
√ 1+
1 we have another equation:
( 2+ λ )
2

4 2 4
3 +2λ − =0

√ √
1
( 2+1 λ )
2
1+ 1
1+ ( 2+ λ ) 1+
( 2+ λ )2 ( 2+ λ )
2

Also, two other values of λ :

λ=−1.03873∧λ=−3.1317

Last step is to compute value of x and y according to each value of λ :


With λ=3.13935 :

−2 −2
y= = =−1.96318

√ 1+
1
( 2+ λ )
2
√ 1+
1
( 2+3.13935 )
2

y −1.96318
x= = =−0.38199
2+ λ 2+3.13935

With λ=−2.31197 :

−2 −2
y= = =−0.595631

√ 1+
1
( 2+ λ )
2
√ 1+
1
( 2−2.31197 )
2

y −0.595631
x= = =1.90925
2+ λ 2−2.31197

With λ=−1.03873

−2 −2
y= = =1.38602

√ 1+
1
( 2+ λ )
2
√ 1+
1
( 2−1.03873 )
2

16 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

y 1.38602
x= = =1.44186
2+ λ 2−1.03873

17 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

With λ=−3.1317 :

−2 −2
y= = =1.49874

√ 1+
1
( 2+ λ )
2
√ 1+
1
( 2−3.1317 )
2

y 1.38602
x= = =−1.3243
2+ λ 2−3.1317

After obtaining all value of x , y in each case of λ , we evaluate f at all the point (x,y). The largest of those
values is the maximum value of f ; the smallest is the minimum value of f

2 3
f (−0.38199 ,−1.96318 )=2 (−0.38199 ) −2 (−0.38199 ) (−1.96318 ) + (−1.96318 )
¿−8.77424
2 3
f ( 1.90925 ,−0.595631 )=2 ( 1.90925 ) −2 ( 1.90925 ) (−0.595631 ) + (−0.595631 )
¿ 9.35357
2 3
f ( 1.44186 ,1.38602 )=2 ( 1.44186 ) −2 ( 1.44186 )( 1.38602 ) + ( 1.38602 )
¿ 2.82364
2 3
f (−1.3243 , 1.49874 )=2 (−1.3243 ) −2 (−1.3243 ) ( 1.49874 ) + ( 1.49874 )
¿ 10.8436

Therefore:

 Maxima value of z=2 x 2−2 xy + y 3 subject to the single constraint x 2+ y 2=4 is


f (−1.3243 , 1.49874 )=10.8436

 Minimum value of z=2 x 2−2 xy + y 3 subject to the single constraint x 2+ y 2=4 is


f (−0.38199 ,−1.96318 )=−8.77424

MATLAB code:
This MATLAB code demonstrates how to plot the contour of a function and a
constraint curve in the same figure. Specifically, the function is z=2 x 2−2 xy + y 3 and the
constraint curve x 2+ y 2=4 in the same figure.

18 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

% Define the range of values for x and y

x = linspace ( -5 , 5 , 100) ;
y = linspace ( -5 , 5 , 100) ;

% Create a grid of x and y values

[X , Y ] = meshgrid (x , y ) ;

% Evaluate the function z at each point on the grid

Z = 2* X .^2 - 2* X .* Y + Y .^3;

% Plot the contour of the

function contour (X , Y , Z , 100) ;


hold on

% Plot the constraint x^2 + y^2 = 4

theta = linspace (0 , 2* pi , 100) ;


r = 2; % set the radius of the circle
x_circle = r * cos (theta); % compute x coordinates
y_circle = r * sin (theta); % compute y coordinates
plot ( x_circle , y_circle , 'k','Color ','red ', 'LineWidth ', 2)

% Set labels

xlabel ('x') ;
ylabel ('y') ;
title ('Contour plot of z = 2x^2 - 2xy + y^3 and constraint x^2 + y^2 = 4') ;

% Adjust the aspect ratio of the plot

pbaspect ([1 1 1])

19 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

The contour plot of function z=2 x 2−2 xy + y 3 and the constraint x 2+ y 2=4

Code explanation:
 theta = linspace(0, 2*pi, 100) - create a 1x100 row vector θ of equally spaced values between
0 and 2π radians with 100 elements.
 x_circle = r*cos(theta) - compute the x-coordinates of the circle using the cos function and θ.
 y_circle = r*sin(theta) - compute the y-coordinates of the circle using the sin function and θ.

20 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

III. Problem 3
Let C be the intersection of the surface x 2+ y 2+ z 2=9 and the cylinder
x + 3 y =4 , z > 0.
2 2

a. Draw the surfaces and the curve C.


b. Find the length of the curve.
c. At any given point (x0, y0, z0) belongs to the curve, draw the unit tangent vector.

Theory: Finding the length of a curve using line integral.


Suppose that a curve C is defined by equation
y=f (x ),

where {f isacontinous
≤ x≤b
We obtain a polygonal approximation to C by dividing the interval [a , b] into n
subintervals with endpoints x 0 , x 1 ,... , x n and equal with ∆ x . If y i=f (x i), and then the
point Pi (x , y ) lies on C and the polygon with vertices P0 , P 1 , ... , P n, Illustrated in the
below figure, is an approximation to C.

The length L of is approximately the length of this polygon and the approximation gets better as
we let n increase. Therefore we define the length L of the curve C with equation y=f (x ),a ≤ x ≤ b
, as the limit of the lengths of these inscribed polygons (if the limit exists):
n
L=lim ∑ ¿ Pi−1 P i∨¿ ¿
n → ∞ i=1

21 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

If we let ∆ x i=x i−x i−1 and ∆ y i = y i− y i−1, then

|Pi−1 P i|=√ ( x i−x i−1 )2+ ( y i− y i−1 )2=√ ( ∆ x )2 + ( ∆ y )2

By applying the Mean Value Theorem to f on the interval [ x i−1 , x i ] , we find that there exist a number
x i between x i−1 and x isuch that
¿

f ( x i ) −f ( x i−1 )=f ( x ) ( x i−x i−1 )


'
→ ∆ y i=f ( x i ) ∆ x
Thus we have:

|Pi−1 P i|=√ 12+ [ f ' ( x ) ]


2
dx

By the definition, this integral exists because the function g ( x )= 12+ [ f ' ( x ) ] is continuous. Thus we √ 2

have proved the following theorem: If f 'is continuous on [a,b], then the length of the curve y=f (x ) ,
a ≤ x ≤ b , is
b

a

L=∫ 1 + [ f ( x ) ] dx
2 ' 2

Then we have another assumption that C can be described by the parametric equations x=f ( t ) and
dx '
y=g ( t ), α ≤ x ≤ β ,where =f ( t ) > 0. This means that C is traversed once, from left to right, as t
dt
increased from α to β and f ( α )=a, f ( β )=b. We obtain:

√(
b β

√ )( )
dx 2 dy 2
2
L=∫ 1 + [ f ( x ) ] dx =∫
2 '
+ dx
a α dt dt

The length of space curve is defined in exactly the same way. Suppose that the curve has the
vector equation r (t )=⟨ f (t), g(t),h (t)⟩ , a ≤ x ≤ b, or, equivalently, the parametric equations
x=f (t), y=g(t ), z=h (t), where f ' , g ' and h ' are continuous. If the curve is traversed exactly once
as t increases from a to b, then it can be shown that its length is

√(
b β

√ [ f ( x ) ] + [ g ( x ) ] +[ h ( x ) ] dx=∫ )( )( )
dx 2 dy 2 dz 2
2 2 2
L=∫ ' ' '
+ + dt
a α dt dt dt

22 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

Tangent vectors:
In mathematics, a tangent vector is a vector that is tangent to a curve or surface at a given point.
Tangent vectors are described in the differential geometry of curves in the context of curves in R n.
More generally, tangent vectors are elements of a tangent space of a differentiable manifold. Tangent
vectors can also be described in terms of germs. Formally, a tangent vector at the point x is a linear
derivation of the algebra defined by the set of germs at x .
Let r (t ) be a parametric smooth curve. The tangent vector is given by r ' ( t ) where we have used a
prime instead of the usual dot to indicate differentiation with respect to parameter t . The unit
tangent vector is given by
'
r (x )
T ( x )=
|r ( x )|

MATLAB Code:

a) Draw the surfaces and the curve C.


% Plot the the surface x^2 + y^2 + z^2 = 9

f = @( x , y , z ) x .^2 + y .^2 + z .^2 -9;


fimplicit3 ( f , [ -3 3 -3 3 0 5 ] , 'c' ) ; % plot the surface in cyan color
daspect ([1 1 1]) % set the aspect ratio of axes to 1 1 1
xlabel ('x') ;
ylabel ('y') ;
zlabel ('z') ;
hold on ; % retain the plot for the next plot

The surface of x + y + z =9 2 2 2

23 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

24 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

%Plot the surface x^2 +3y^2 = 4


g = @( x , y ) x .^2 + 3*( y .^2) -4;
fimplicit3 (g , [ -3 3 -3 3 0 5 ] , 'g') ; % plot the surface in green
color
daspect ([1 1 1]) % set the aspect ratio of axes to 1 1 1
xlabel ('x') ;
ylabel ('y') ;
zlabel ('z') ;
hold on ; % retain the plot for the next plot

The cylinder x + 3 y =42 2

25 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

% Draw the curve C as the interection of 2 surfaces :


syms t ;
X = cos (t ) .*2;
Y = sin (t ) .*(2/ sqrt (3) ) ;
syms t ;
X = 2.* cos ( t ) ;
Y = sin (t ) .*(2/ sqrt (3) ) ;
Z = sqrt (9 - 4.* cos ( t ) .^2 - 4/3.* sin ( t ) ^2) ; % calculate the z-coordinate of the curve
curveC = fplot3 (X , Y , Z , [ 0 2* pi ] , 'linewidth ', 5) ;
curveC . Color = 'r'; % plot the curve with red color
daspect ([1 1 1]) % set the aspect ratio of axes to 1 1 1
xlabel ('x') ;
ylabel ('y') ;
zlabel ('z') ;
title (" Intersection curve of the surfaces x ^2 + y ^2 + z ^2 = 9 and the cylinder x ^2 + 3 y ^2 = 4 , z >
0")

The surfaces and the curve C

26 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

% Draw the curve C as the interection of 2 surfaces without line :

syms t ;
X = cos ( t ) .*2;
Y = sin ( t ) .*(2/ sqrt (3) ) ;
Z = sqrt (9 - 4.* cos ( t ) .^2 - 4/3.* sin ( t ) ^2) ; % calculate the z-coordinate of the curve
curveC = fplot3 (X , Y , Z , [ 0 2* pi ] , 'linewidth ', 3) ;
curveC . Color = 'b'; % plot the curve with blue color
daspect ([1 1 1]) % set the aspect ratio of axes to 1 1 1
xlabel ('x') ;
ylabel ('y') ;
zlabel ('z') ;
title (" The intersection curve C of two surfaces ") ;

The intersection curve C

27 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

b) Find the length of the curve C

Hand-writing solution:

First we represent x and y through parameter t :

{
x=2 cos t
2
y= sin t (1)
√3
0≤t≤2π

Substituing x and y into the equation of the cylinder x 2+ 3 y 2=4 , we have:

√ 2 4
z= 9−4 cos ( x ) − sin ( t )
3
2

Therefore the curve C is defined as:

{√
x=2 cos t
2
y= sin t
√3 (2)
4
z= 9−4 cos ( x )2− sin ( t )2
3

The length of the curve C is:

√(

L=∫
0 dt) ( )( )
dx 2 dy 2 dz 2
+
dt
+
dt
dt


¿∫ √ ¿ ¿ ¿ ¿
0

¿ 10.3677

28 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

Solving by MATLAB:

% Calculate the length of the intersection curve C

func = @( x ) sqrt (( -2.* sin ( x ) ) .^2 + (2./ sqrt (3) .* cos ( x ) ) .^2 + (((8/3) .* cos ( x) .* sin ( x ) ) ./
sqrt ((8/3) .* sin ( x ) .^2 + 5) ) .^2) ;

% Use the integral function to evaluate the integral of the integrand over the interval [0 , 2pi]

Length = integral ( func , 0 , 2* pi ) ;

% Display the length of the curve C

fprintf ('Length of the curve C is: ') ;


disp ( Length ) ;

Result:

The length of the curve C by MATLAB


c) At any given point ( x 0 , y 0 , z 0 )belongs to the curve, draw the unit tangent vector. We have (C) :

{√
x=2 cos(t)
2
y = sin ⁡(t)
√3 (3)
2 4
z= 9−4 cos ( x ) − sin (t)2
3

Let
r ( t )=2 cos ( t ) i⃗ +
2
√3 √ 2 4
sin ( t ) ⃗j + 9−4 cos ( x ) − sin ( t ) ⃗k
3
2

29 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science
2 8 sin(t)cos (t)
r ' ( t ) =−2sin ( t ) ⃗i + cos ( t ) ⃗j+ ¿
√3 3¿¿¿

Therefore, we can implement this MATLAB code:

% Plot the unit tangent vector at anypoint on the curve C


t = linspace (0 , 2* pi , 100) ;
% Vector r(t)s components : x_t , y_t , z_t
x_t = 2.* cos ( t ) ;
y_t = 2./ sqrt (3) .* sin ( t) ;
z_t = sqrt (9 - 4.* cos ( t ) .^2 + 4./3.* sin ( t ) .^2) ;
% Vector r '(t) components : m, n, p
x = -2.* sin ( t ) ;
y = 2./ sqrt (3) .* cos ( t ) ;
z = (8.* cos ( t ) .* sin ( t ) ) ./ sqrt (3.*(8.* sin ( t ) .^2 + 15) )
l = sqrt ( x .^2 + y .^2 + z .^2) ; % length of the tangent vector
m = -2* sin ( t ) ./ l ;
n = (2/ sqrt (3) .* cos ( t ) ) ./ l ;
p = (8.* cos ( t ) .* sin ( t ) ) ./ sqrt (3.*(8.* sin ( t ) .^2 + 15) ) ./ l ;
figure
quiver3 ( x_t , y_t , z_t , m , n , p ) ; % plot the unit tangent vector at each point on the curve
daspect ([1 1 1]) % set the aspect ratio of axes to 1 1 1
xlabel ('x') ;
ylabel ('y') ;
zlabel ('z') ;
title ('Unit tangent vectors to C ') ;

Unit tangent vectors to C


30 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

Code explanation:

 l = sqrt(x.∧ 2 + y.∧ 2 + z.∧ 2) - calculates the length of the unit tangent vector at each
point on the curve.
 m = -2*sin(t)./l - calculates the x-component of the unit tangent vector at each point on
the curve.
 n = (2/sqrt(3).*cos(t))./l - calculates the y-component of the unit tangent vector at each
point on the curve.
 p = (8.*cos(t).*sin(t))./sqrt(3.*(8.*sin(t).∧ 2 + 15))./l - calculates the z-component of
the unit tangent vector at each point on the curve.
 quiver3(x_t, y_t, z_t, m, n, p) - plots the unit tangent vector at each point on the curve as
an arrow.

31 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

C. Conclusion
In conclusion, this report has presented the main findings and
recommendations of our project in solving three problems at Calculus 2 and
using the MATLAB for sketching the graph of curve and calculating the
values in each problem. We would like to thank our assistant teacher,
Mr.Phiet , for his valuable guidance and feedback throughout the course of
this project. He has been very supportive and helpful in clarifying our
doubts and providing us with useful resources and suggestions. His
expertise and experience have greatly enhanced the quality and rigor of our
work. We are grateful for his time and effort in mentoring us.

32 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

33 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

34 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

35 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

36 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

37 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

38 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

39 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

40 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

41 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

42 | P a g e
Ho Chi Minh City University of Technology
Faculty of Applied Science

43 | P a g e

You might also like