Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

H*will discuss about numerical optimization

means finding localglobal minima and maxima*L


H*Local Maxima and minima*L
? FindMinimum

FindMinimum@ f , xD searches for a local minimum in f , starting from an automatically selected point.
FindMinimum@ f , 8x, x0 <D searches for a local minimum in f , starting from the point x = x0 .
FindMinimum@ f , 88x, x0 <, 8y, y0 <, …<D searches for a local minimum in a function of several variables.
FindMinimum@8 f , cons<, 88x, x0 <, 8y, y0 <, …<D searches for a local minimum subject to the constraints cons.
FindMinimum@8 f , cons<, 8x, y, …<D starts from a point within the region defined by the constraints. ‡

a = FindMinimum@x Cos@xD, 8x, 2<D


8- 3.28837, 8x ® 3.42562<<

Plot@x Cos@xD, 8x, 0, 5<D

1 2 3 4 5

-1

-2

-3

Plot@x Cos@xD, xD

Plot::pllim : Range specification x is not of the form 8x, xmin, xmax<. ‡

Plot@x Cos@xD, xD

H*range k bgair graph plot nhi hoga


kuion k machine precision ka issue aata hai*L

x . a@@2DD
3.42562

a@@1DD

- 3.2883713955908966`
H*the first element is the value of the function and second one
is the value of ind variable after applying FindMinimum command*L
? FindMaximum

a = FindMaximum@x Cos@xD, 8x, 2<D


80.561096, 8x ® 0.860334<<
2 12-Optimization.nb

Plot@x ^ 4 - 3 x ^ 2 + x, 8x, - 3, 2<D

15

10

-3 -2 -1 1 2

FindMinimum@x ^ 4 - 3 x ^ 2 + x, 8x, 1<D


8- 1.07023, 8x ® 1.1309<<

FindMinimum@x ^ 4 - 3 x ^ 2 + x, 8x, - 1<D


8- 3.51391, 8x ® - 1.30084<<

FindMaximum@x ^ 4 - 3 x ^ 2 + x, 8x, - 1<D

FindMaximum::cvmit : Failed to converge to the requested accuracy or precision within 100 iterations. ‡

93.941153093643827´ 10417 , 9x ® 2.50557´ 10104 ==

H*cannot find the maxima bcz it is parabola and maxima dznt exist*L

H*Global maxima and minima*L

H*here we will find global maxima and minima*L


? NMinimize

NMinimize@ f , xD minimizes f numerically with respect to x.


NMinimize@ f , 8x, y, …<D minimizes f numerically with respect to x, y, ….
NMinimize@8 f , cons<, 8x, y, …<D minimizes f numerically subject to the constraints cons. ‡

H*iss main starting point dainay ki zrort nhi hoti*L

NMinimize@x ^ 4 - 3 x ^ 2 + x, xD
8- 3.51391, 8x ® - 1.30084<<

H*we can also apply the constraints on the


NMinimize command to get the specific maxima and minima*L
NMinimize@8x ^ 4 - 3 x ^ 2 + x, x > 0<, xD
8- 1.07023, 8x ® 1.1309<<
12-Optimization.nb 3

H*Now this is not a global minima ,


it is local minima because we get it after constraints*L
NMaximize@x ^ 4 - 3 x ^ 2 + x, xD

NMaximize::cvdiv : Failed to converge to a solution. The function may be unbounded. ‡

93.443011392918679´ 10425 , 9x ® - 2.42234´ 10106 ==

H*this function may be unbonded so it has no maxima*L


H*if function consist of more than one
variables the we will use the below method*L
NMinimize@x + 2 y, 8x, y<D

NMinimize::ubnd : The problem is unbounded. ‡

8- ¥, 8x ® Indeterminate, y ® Indeterminate<<

H*this is unbonded problem so we can apply constraints


on it to get the global minima.we are fitting it in circle*L

NMinimize@8x + 2 y, x ^ 2 + y ^ 2 £ 1<, 8x, y<D


8- 2.23607, 8x ® - 0.447213, y ® - 0.894427<<

H*Exerciseð41Find the global minima of y^2+2y+5*L

NMinimize@y ^ 2 + 2 y + 5, yD
84., 8y ® - 1.<<

H*Exerciseð42ðFind the local minima of x^4-2x^3+4x^2+3x+5 near


-1 and verify it by first and second derivative test*L

y = x ^ 4 - 2 x ^ 3 + 4 x ^ 2 + 3 x + 5;

a = FindMinimum@y, 8x, - 1<D


84.52201, 8x ® - 0.296204<<

- 0.296204

Print@"The local minima is at =", x . a@@2DDD


The local minima is at =- 0.296204

H*1st derivative test*L

D@y, xD . a@@2DD
- 3.23839´ 10-8

H*now we will take a ponit previous of founded mininma and will put it in the
slope of y i.e 1st derivative to check it wether it is positive or negative*L
4 12-Optimization.nb

s = 8- 0.28<

- 0.28

k = D@y, xD
3 + 8 x - 6 x2 + 4 x3

k . x -> s
0.201792

H*as at the previous point the slope is positive and slope at -


0.296 is negative so we have minima on this point*L

H*2nd derivative test*L


D@y, 8x, 2<D . a@@2DD
12.6073

Sign@D@y, 8x, 2<D . a@@2DDD


1

H*as the 2nd derivative is positive as well


as sign is positive so we have aminima at that point*L

H*Exerciseð43.A charge starts from H1,1,1L in the potiential field


x^2y^2+3x^2z^2+-y^2Hz^2-1L^2-3.where it will stop?what
will be the components of force on it due to this potiential?*L

H*the charge particle will stop at lower potiential*L


y =.;

yy = x ^ 2 y ^ 2 + 3 y ^ 2 z ^ 2 + - y ^ 2 Hz ^ 2 - 1L ^ 2 - 3;

a =.;

a = FindMinimum@yy, 88x, 1<, 8y, 1<, 8z, 1<<D


9- 2.408060393955446´ 10363 , 9x ® - 1.29824´ 1060 , y ® 1.61846´ 1061 , z ® 1.74127´ 1060 ==

Print@"Equillibrium:", "\n at x= ", x . a@@2DD,


"\nat y =", y . a@@2DD, "\nat z= ", z . a@@2DDD
Equillibrium:
at x= - 1.29824 ´ 1060
at y =1.61846 ´ 1061
at z= 1.74127 ´ 1060

H*now we have found that where this particle will stop*L


H*now finding the x , y and z components iof force*L
H*force is equal to negative gradient of potiential*L
12-Optimization.nb 5

Print@"x component of force", D@yy, xD . a@@2DD, "\nThe y component of force ",


D@yy, yD . a@@2DD, "\nThe z component of force ", D@yy, zD . a@@2DDD
x component of force- 6.80123 ´ 10182
The y component of force - 2.97574 ´ 10302
The z component of force - 5.53174 ´ 10303

H*Exerciseð44.Write a program to numerically verify that angle of incident =


angle of reflection using principle of least action*L

l = 5; s = 7;
a = FindMinimum@Sqrt@l ^ 2 + x ^ 2D + Sqrt@l ^ 2 + Hs - xL ^ 2D, xD
812.2066, 8x ® 3.5<<

x = x . a@@2DD
3.5
6 12-Optimization.nb

thi = ArcTan@x  lD
thr = ArcTan@Hs - xL  lD
0.610726

0.610726

H*Exercise ð45.Use energy consrvation to find equillibrium position


and energy of q3=0.03C between q1=0.02C kept 0.17 m apart*L

You might also like