Use the function fminsearch to find the values of x y and z
Use the function “fminsearch” to find the values of x, y, and z that maximize the function f(x, y, z) = 1000*cos(3*x +2*y + z + 1)*e^-(x^2 + y^2 + z^2). What is the maximum value of f at these values for x, y, and z?
Hint: Use a number of random starting guesses for x, y, z between -5 and +5.
Introduction to Matlab version 3.
Solution
>>f=@(x) 1000*cos(3*x(1) +2*x(2) + x(3) + 1)*exp(-(x(1)^2 + x(2)^2 + x(3)^2))
f =
@(x)1000*cos(3*x(1)+2*x(2)+x(3)+1)*exp(-(x(1)^2+x(2)^2+x(3)^2))
>>[x,fval] = fminsearch(f,[-1,1,2])
x =
0.4027 0.2685 0.1342
 fval =
-750.4594
-----------------------------------
>> [x,fval] = fminsearch(f,[1,1,2])
x =
1.6282 1.0855 0.5427
 fval =
-10.9627
--------------------------------------
 >> [x,fval] = fminsearch(f,[2,1,-2])
x =
1.6282 1.0855 0.5428
 fval =
-10.9627
------------------------------------
>> [x,fval] = fminsearch(f,[2,3,-5])
x =
1.6282 1.0855 0.5428
 fval =
-10.9627
---------------------------------------
 >> [x,fval] = fminsearch(f,[4,5,-5])
x =
4.2345 2.8229 1.4114
 fval =
-2.5719e-10
-------------------------------------------------
>> [x,fval] = fminsearch(f,[2,1,-5])
x =
0.4027 0.2684 0.1343
 fval =
-750.4594


