Matlab Project: Partial Derivative and Application
Matlab Project: Partial Derivative and Application
Table of Contents
A. THEORY......................................................................................................................................................2
1. Function of variables................................................................................................................................2
a. Function of two variables.....................................................................................................................2
b. Graphs...................................................................................................................................................2
2. Limits and continuity...............................................................................................................................2
a. Limits....................................................................................................................................................2
b. Continuity.............................................................................................................................................3
c. Functions of Three or More Variables...............................................................................................3
3. Partial derivatives....................................................................................................................................3
a. Interpretations of Partial Derivatives.................................................................................................3
b. Functions of More Than Two Variables.............................................................................................3
c. Higher Derivatives................................................................................................................................3
d. Partial Differential Equations.............................................................................................................4
e. Tangent Planes and Linear Approximations.....................................................................................4
f. Linear Approximations........................................................................................................................4
4. Differentials..............................................................................................................................................4
a. The function of multivariable..............................................................................................................4
b. The chain rule......................................................................................................................................4
c. Maximum and minimum values..........................................................................................................5
B. APPLICATION:..........................................................................................................................................6
1. Chain rule.................................................................................................................................................6
2. Differential (Change in variable)............................................................................................................7
3. Differential (Error)..................................................................................................................................8
4. Higher order derivative...........................................................................................................................9
5. Tangent plane.........................................................................................................................................12
6. Approximation.......................................................................................................................................13
7. Lagrange multiplier...............................................................................................................................14
8. Maxima-Minima.....................................................................................................................................16
C. REFERENCES...........................................................................................................................................18
1|Page
MATLAB PROJECT: PARTIAL DERIVATIVE AND APPLICATION
A. THEORY
1. Function of variables
a. Function of two variables
b. Graphs
Definition: If f is a function of two variables with domain D, then
the graph of f is the set of all points (x, y, z) in R3 such that z =
f(x,y) and (x,y) is in D.
lim f ( x , y )=L
( x , y ) → ( a , b)
2|Page
MATLAB PROJECT: PARTIAL DERIVATIVE AND APPLICATION
if for every number ε > 0, there is a corresponding number δ >0such that if ( x , y ) ∈ D and
0< √ (x−a)2+( y −b)2< δ then |f ( x , y )−L|< ε
b. Continuity
If f is defined on a subset D of Rn, then lim ¿x → a f ( x ) =L¿ means that for every number ε > 0there is
a corresponding number δ >0such that:
3. Partial derivatives
a. Interpretations of Partial Derivatives
The partial derivatives f ( a , b ) and f ( a ,b ) can be interpreted
x y
If uis a function of n variables, u=f ( x 1 , x 2 , … … xn ), its partial derivative with respect to the ith
variable x iis
∂u f ( x1 , … … , xi−1 , x i +h , x i+1 , … … , x n ) −f ( x 1 , … … , x i , … … , x n )
=lim
∂ x i h→ 0 h
∂u ∂ f
and we also write: = =f =f =D i f
∂ x i ∂ xi x i i
c. Higher Derivatives
If f is a function of two variables, then its partial derivatives f x and f y are also functions of two
variables, so we can consider their partial derivatives ( f x ) x,( f x ) y, ( f y ) x and ( f y ) y , which are called the
second partial derivatives of f . If z=f ( x , y ), we use the following notation:
∂2 f ∂2 z
( f x ) x =f xx= =
∂ x2 ∂ x2
∂2 f ∂2 z
( f x ) y =f xy= =
∂ y ∂x ∂ y∂ x
∂2 f ∂2 z
( f y ) x =f yx= =
∂x ∂ y ∂x ∂ y
3|Page
MATLAB PROJECT: PARTIAL DERIVATIVE AND APPLICATION
2 2
∂ f ∂ z
( f y ) y =f yy = =
∂ y2 ∂ y2
Clairaut’s Theorem: Suppose f is defined on a disk Dthat contains the point ( a , b ). If the functions
f xy and f yxare both continuous on D, then
f xy ( a , b ) =f yx ( a , b )
d. Partial Differential Equations
Partial derivatives occur in partial differential equations that express certain physical laws.
∂2 u ∂2 u
Laplace’s equation: + =0. Solutions of this equation are called harmonic functions;
∂ x2 ∂ y2
they play a role in problems of heat conduction, fluid flow, and electric potential.
∂2 u 2
2 ∂ u
The wave equation: 2 =a describes the motion of a waveform, which could be an ocean
∂t ∂ x2
wave, a sound wave, a light wave, or a wave traveling along a vibrating string.
f. Linear Approximations
Theorem: if the partial derivatives f x and f y exist near ( a , b ) and are continuous at ( a , b ) ,then f is
differentiable at ( a , b ) .
4. Differentials
a. The function of multivariable
z=f ( x , y ), then the differential dz is defined by:
∂z ∂z
dz=f x ( x , y ) dx +f y ( x , y ) dy= dx + dy
∂x ∂y
The Function of three or more variables can be written as w=f ( x , y , z ). Then, the differential dw is
defined: w=f ( x , y , z )
∂w ∂w ∂w
dw= dx+ dy + dz
∂x ∂y ∂z
b. The chain rule
x=x (s , t)
z=z (x , y ) and { y= y ( s , t)
4|Page
MATLAB PROJECT: PARTIAL DERIVATIVE AND APPLICATION
Then:
∂z ∂z ∂x ∂ z ∂ y
= +
∂s ∂ x ∂ s ∂ y ∂ s
∂z ∂z ∂x ∂ z ∂ y
= +
∂t ∂ x ∂t ∂ y ∂t
The chain rule (general version): suppose u that is a differentiable function of the n variables
x 1 , x 2 , … , x n and each x i is a differentiable function of the m variables t 1 , t 2 , … , t m. Then u is a function
of t 1 , t 2 , … , t m and for each i=1,2 , … , m,
∂ u ∂u ∂ x1 ∂ u ∂ x2 ∂u ∂ x n
= + +…+
∂ t i ∂ x 1 ∂t i ∂ x 2 ∂ t i ∂ x n ∂ ti
c. Maximum and minimum values
Theorem: If f has a local maximum or minimum at ( a , b )and the first-order partial derivatives of f
exist there, then f x ( a , b )=0and f y ( a ,b )=0 .
Second Derivatives Test: Suppose the second partial derivatives of f are continuous on a disk with
center ( a , b ), and suppose that f x ( a , b )=0and f y ( a ,b )=0 . [that is, ( a , b ) is a critical point of f ]. Let
2
D=D ( a , b )=f xx ( a , b ) f yy ( a ,b )−[ f xy ( a , b ) ]
(a) If D>0and f xx ( a , b ) >0 , then f ( a ,b )is a local minimum.
(b) If D>0and f xx ( a , b ) <0 , then f ( a ,b )is a local maximum.
(c) If D<0 ,then f ( a ,b )is not a local minimum or maximum.
Method of Lagrange Multipliers: To find the maximum and minimum values of f ( x , y , z ) subject to the
constraint g ( x , y , z ) =k (assuming that these extreme values exist and ∇ g ≠ 0on the surface
g ( x , y , z ) =k]:
5|Page
MATLAB PROJECT: PARTIAL DERIVATIVE AND APPLICATION
B. APPLICATION:
All of the problems in this heading were completely solved by MATLAB software.
1. Chain rule
Sometimes we want to determine the change of parameter in some of or objects during a period of
time but when the time changes, the other inside that parameter will change as well. of Its moment
inertia is
I= m(r12+r22)/2,
where m is the mass. The two radius (r1 and r2) are increasing at a rate of f1(t) and f2(t) (centimeter per
second), respectively. When time changes, not only I changes respect to time, but also 2 radiuses gain
the change, too. That’s why we need to apply the Chain rule to solve this problem. For example: An
annular cylinder has an inside radius of r1 and an outside radius of r2.
Problem: The two radius (r1 and r2) are increasing at a rate of 2t and 2t+1 centimeter per second,
respectively. Find the rate at which I changes at the time t=6 seconds. Assume the mass is 1 kg.
Solution:
_First, we denote r1, r2, t by “syms” command and compute the function I= m(r12+r22)/2,
>> syms r1 r2 t
>> I=(1/2)*(r1^2+r2^2);
_Then we also type the pressure and temperature function:
>> r01=2*t;
>> r02=2*t+1;
dI ∂I dr ∂I dr
_Next, we apply the chain rule = ∂ r * 01 + ∂ r * 0 2 and compute r01, r02 to derivative
dt 1 dt 2 dt
function to obtain the one which only consists of variable “t”
>> diffI=diff(I,r1)*diff(r01,t)+diff(I,r2)*diff(r02,t);
>> I_t=subs(diffI,[r1 r2] ,[r01 r02])
I_t = 8*t + 2
_Replace t by 6, we have the result :
>> I_6=subs(I_t,t,6)
I_6 =50
6|Page
MATLAB PROJECT: PARTIAL DERIVATIVE AND APPLICATION
Total command :
Usually, the system will run at the most effective condition as the Lagrangian function shows
the smallest value.
Problem: Consider a pendulum-clock consists of a massless string that hangs a 0.2-kilogram-of-mass
body. Its oscillation in the form of the Lagrangian function is:
1
L= m v 2−mgl(1−cos ( ∝ ))
2
If the producer decides to increase the velocity of the oscillator from 1 m/s to 1.2 m/s and
decrease the length of the string from 0.5 m to 0.45 m, how does it affect the motion of the clock?
Assume ∝=30 ° and g = 10 m/s2.
Solution:
1 2
_In first step, we compute the set of 8 variables and the main function: ¿ m v −mgl (1−cos ( ∝ ) )
2
>> syms m v g l a dv dl L
>> L=0.5*m*v^2-m*g*l*(1-cos(a));
7|Page
MATLAB PROJECT: PARTIAL DERIVATIVE AND APPLICATION
∂L
_Lv is the first partial derivative of L respect to v and to l, respectively. The differentiate: dL = *
∂v
∂L
dv + * dl
∂l
>> Lv=diff(L,v,1);
>> Ll=diff(L,l,1);
>> dL=Lv*dv+Ll*dl;
dL =
dv*m*v + dl*g*m*(cos(a) - 1)
_Then, to find the result, we compute those variables with their corresponding value:
>> vpa(subs(dL, [m v g l a dv dl], [0.2 1 10 0.5 pi/6 0.2 -0.05]))
ans =
0.053397459621556135323627682924706 ≈0.05
Conclusively, as the result indicated above, these changes cause the increase in the energy
compsumtion of the system that should not be applied due to the economic efficiency.
Total command :
3. Differential (Error)
Problem: A capacitor with a capacitiance of C = 5.0 coulombs/volt holds an initial charge of Q = 350
coulombs. The capacitor is attached to a resistor with a resistance of Zc = 8.0 volts. sec/coulomb. The
potential of the system is calculated by the following equation:
U =Q∗Z c∗¿ ω
Due to the equipment errors showing: ΔZc = 0.2% and ΔQ = 0.1%. What is the maximum
errors of U could appear?
Solution:
8|Page
MATLAB PROJECT: PARTIAL DERIVATIVE AND APPLICATION
_Let ω = 100*pi rad/s
_First, let’s compute the variable and function:
>> syms U Q Zc dQ dZc w
>> U = Q*w*Zc;
∂U ∂U
_Use the first partial derivative of U respect to Q and Zc. dU = * dQ + * dZc
∂Q ∂ Zc
>> UQ = diff (U,Q);
>> Uzc = diff (U,Zc);
>> dU = UQ*dQ + Uzc*dZc;
Total command:
9|Page
MATLAB PROJECT: PARTIAL DERIVATIVE AND APPLICATION
λ−4
ε= 2
(λ−4) +T
2 ( λ :10−2 nm; T :10−2 ℃ )
e
Solution:
(λ−4 )× 1× 2
_First, we denote λ by x, T by y, z by A and compute the function: A= ε. l. C = 2 2
e( λ−4 ) +T
>> syms x y z
>> z= 2*(x-4)/exp((x-4)^2 + y^2);
th ∂4 A ∂ 4 z
_In next step, we use 4 -order partial derivative ( = ) function as:
∂ λ4 ∂ x 4
>>simplify(diff(z,x,4));
_Then, to obtain and compare the resolution of the graph between the main function z and its 4th
∂4 z
derivative we use the command “ezsurf”
∂x4
>> ezsurf(z,[0,6,0,6] )
>> ezsurf(simplify(diff(z,x,4)),[0,6,0,6] )
_From figure 1a and b, we can conclude that with 4th derivative respect to x, we can investigate the
impurity with have relatively lower band than the band of main substance lycopene. By using the
∂ 4 z th
derivative of (5 derivative of z), we can obtain 2 positive extrema of the graph (use “vpa”
∂x4
command to get the absolute result):
>> solve(diff(z,x,5));
>>vpa(ans,3)
ans = 2.66 4.44
_So, lycopene has nearly λmax = 444 nm (absorbs violet light) and the impurity compound has its λmax =
266 nm.
_Lastly, to find the max absorbance of lycopene at this wavelength in T = 30oC and T = 50oC, we apply
the “sub” command:
>> vpa(subs(z,[x y],[4.44 0.5]))
ans = 0.56
>> vpa(subs(z,[x y],[4.44 0.3]))
ans = 0.66
10 | P a g e
MATLAB PROJECT: PARTIAL DERIVATIVE AND APPLICATION
exp(- (x - 4)2 - y 2) (2 x - 8)
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
3
-0.8 2
1
1 0
1.5 2 2.5 3 -1
3.5 4 -2
4.5 5 5.5 6 -3
y
x
20 exp(- (x - 4)2 - y 2) (2 x - 8) + 10 exp(- (x - 4)2 - y 2 ) (8 x - 32) -...- exp(- (x - 4)2 - y 2 ) (2 x - 8)2 (8 x - 32)
30
20
10
-10
-20
3
2
1
-30
0
-1
1 2 -2
3 4 5 -3
6 y
x
Total command:
11 | P a g e
MATLAB PROJECT: PARTIAL DERIVATIVE AND APPLICATION
5. Tangent plane
On April 14th, 2018, in the order of US President Donald Trump, the allies involving the US, UK
and France had launched more than 100 missiles against the Syrian chemical weapons facilities in
response to a chemical weapons attack in a Damascus suburb a week ago. The strike began at 4am
Syrian time (0200 GMT), contained planes and ship-launched missiles and identified three targets: a
scientific research center in Damascus, a chemical weapons storage facility west of Homs, and another
storage site and command post nearby.
Problem: In order of White House, a US military Jet F11 took off from a military base. Its trajectory
was a function of z=f ( x , y )=85.67+ x y 2−12.34 y −3 x 2−8 xy . At the point with coordinates (23; 18)
(m) from the airport, the jet launched a Tomahawk towards a Syrian chemical facility, one of above the
targets, on the hill with the coordinates (120; 10; 1437). The path of the missile is a straight-line
tangent to the trajectory of the plane at the point of the launch. Will missile hit the target? Knowing the
allowable precision for jet pilot is not above 5%.
Solution:
_First, we need to compute the variable x, y and the function of jet’s trajectory:
>>syms x y
12 | P a g e
MATLAB PROJECT: PARTIAL DERIVATIVE AND APPLICATION
>>z=85.67+x*y^2-12.34*y-3*x^2-8*x*y;
_Use the partial derivative, we find the derivative function of f respect to x and y coordinate
>> zx=diff(z,x);
>> zy=diff(z,y);
6. Approximation
Problem: A pharmaceutical corporation has 2 plants that produce the same over-the counter medicine:
Hydrastis canadensis and Panax ginseng. The total revenue for the product is given by equation
R=200 H +200 P−4 P2−8 HP−4 H 2, where H and P is the number of units produced at plant
Hydrastis canadensis and Panax ginseng, respectively. Find a linear approximation when H is near 25
and P is near 85. Use it to estimate the marginal produce when H is 80 and P is 63 and check when
compute directly with function R above.
Solution:
_At first step, we compute the function of marginal revenue:
>> syms P H
>> R=200*H+200*P-4*P^2-8*H*P-4*H^2;
13 | P a g e
MATLAB PROJECT: PARTIAL DERIVATIVE AND APPLICATION
_Then, we find the function RP and RH
>> RH=diff(R,H);
>> RP=diff(R,P);
7. Lagrange multiplier
A silo is a large, round tower for storing bulk materials. In Canadian, Austrian and American
agriculture, farmers use silo to store a large amount of grains, fermented foods, wood, and sawdust.
This structure originally is a cylinder with a hemisphere as a stainless-steel cap on the top.
Problem: Mr. John, an engineer, wants to design a parameter of a silo for his friend, Mr. Tom-a
farmer, to store the corn after harvesting. What is the minimum cost to build a silo of 1000 m 3 as Mr.
Tom desired? Consider the steel costs $4/m2 to build and the wall costs
$1/m2.
Solution:
_First, we type the function in software, with V total = V hemisphere + V cylinder; C
= 1*(S surrounding cylinder) + 4*(S hemisphere)
>> syms R h
>> V=pi*(R^2)*h+(2/3)*pi*R^3;
>> C=4*(2*pi*R^2)+1*(2*pi*R*h);
>> g=V-1000;
_Let denote “λ” by k, the Lagrange function is written as:
>> syms k
Figure 2. A silo ‘s model
>> L = C+k*g;
14 | P a g e
MATLAB PROJECT: PARTIAL DERIVATIVE AND APPLICATION
st
_Use the 1 partial derivative respect to h ,R, k,
>> LR=diff(L,R);
>> Lh=diff(L,h);
>> Lk=diff(L,k);
>> Solution=solve(LR,Lh,Lk,R,h,k);
>> R=Solution.R
R=
(75*((3^(1/2)*1i)/2 - 1/2)^2*(-(4*pi)/75)^(2/3))/(2*pi)
(75*((3^(1/2)*1i)/2 + 1/2)^2*(-(4*pi)/75)^(2/3))/(2*pi)
(75*(-(4*pi)/75)^(2/3))/(2*pi)
>> h=Solution.h
h=
(225*((3^(1/2)*1i)/2 - 1/2)^2*(-(4*pi)/75)^(2/3))/pi
(225*((3^(1/2)*1i)/2 + 1/2)^2*(-(4*pi)/75)^(2/3))/pi
(225*(-(4*pi)/75)^(2/3))/pi
_We choose R, h which have positive value
>> R=(75*(-(4*pi)/75)^(2/3))/(2*pi);
>> h=(225*(-(4*pi)/75)^(2/3))/pi;
>> vpa(subs(C),4)
ans =
826.9
Total command:
15 | P a g e
MATLAB PROJECT: PARTIAL DERIVATIVE AND APPLICATION
16 | P a g e
MATLAB PROJECT: PARTIAL DERIVATIVE AND APPLICATION
8. Maxima-Minima
Problem: A company manufactures two types of athletic shoes: jogging shoes and cross-trainers. The
total revenue from x units of jogging shoes and y units of cross-trainers is given by R(x,y)=
−5x2−8y2−2xy+42x+102y , where x and y are in thousands of units. Find the values of x and y to
maximize the total revenue.
Solution:
_We compute first the function of revenue:
>> syms x y
>> R= -5*x^2-8*y^2-2*x*y+42*x+102*y;
_Apply the 1st and 2nd partial derivative. Δ = fxx * fxy – (fxy)2
>> Rx=diff(R,x);
>> Ry=diff(R,y);
17 | P a g e
MATLAB PROJECT: PARTIAL DERIVATIVE AND APPLICATION
>> A=diff(Rx,x);
>> B=diff(Rx,y);
>> C=diff(Ry,y);
>> Delta= A*C-B^2;
>> [x y]= solve(Rx,Ry)
x =3 y =6
>> subs(A)
ans =-10
>> subs(Delta)
ans =156
_For Δ >0, A<0 => Local maximum
>> subs(R)
ans = 369
Total command:
18 | P a g e
MATLAB PROJECT: PARTIAL DERIVATIVE AND APPLICATION
19 | P a g e
MATLAB PROJECT: PARTIAL DERIVATIVE AND APPLICATION
C. REFERENCE
[1] Peter D. Lax & Maria Shea Terrell. Multivariable Calculus with Applications. Undergraduate
Texts in Mathematics. Springer, Cham, 2017.
[2] Ron Larson & Bruce H. Edwards. Multivariable Calculus 10th Edition. Cengage Learning,
2013.
20 | P a g e