# Minimize: How to work with specific numeric types

This is a question about the use of symbols in Minimize and how to persuade Mathematica to treat them in a specific way (as integers or rationals) that I have not been able to achieve, but analysis of the results of Minimize suggests ought to be possible.

The context is this: I have the following equation and wish to find the minimum value of t0 in closed form for a, b in terms of vx, vy, vz without numeric values (as you will see below I can find a minima for specific numeric values of vx, vy, vz).

t0 = g (-vz Cos[a] - vy Cos[b] Sin[a] - vx Sin[b] Sin[a])


In the code block below, you will see in part 1 an attempt to do this symbolically in terms of the ratio c/d assigned to the key variables vx, vy, vz; Minimize will not do it. In part 2 vx, vy and vz are given a specific exact numerical values and Minimize then delivers a result. However, inspection of the result clearly shows (thanks to the relative primaility of the numerators of vx etc.) that Mathematica is handling the numerators separately.

Code

Block[{g, vx, vy, vz, t0, mint,  a, b , c, d},
t0 = g (-vz Cos[a] - vy Cos[b] Sin[a] -
vx Sin[b] Sin[a]); (* eqn to minimize *)
g = 1/Sqrt[1 - (vx^2 + vx^2 + vx^2)]; (* common initialisation *)
(* Part 1 *)
vx = vy = vz = c/d; (* would like vx etc. elements of Rationals... how? *)
mint = Minimize[{t0, 0 <= b < 2 Pi, 0 <= a < Pi}, {b, a},
Reals]; (* fails *)
Print["t0 minimum = ", mint];
mint = Minimize[{t0, 0 <= b < 2 Pi, 0 <= a < Pi, ,
c ∈ Integers, d ∈ Integers}, {b, a},
Reals]; (* fails *)
Print["t0 minimum = ", mint];
(* Part 2 *)
vx = 7/100; vy = 3/100;
vz = 11/100; (* all v made specific rationals *)
mint = Minimize[{t0, 0 <= b < 2 Pi, 0 <= a < Pi}, {b, a},
Reals]; (* succeeds *)
Print["t0 minimum = ", mint];
]


Result of Part 2:

t0 minimum = {(1/Sqrt[9853])100 (-(11/100) Cos[2 ArcTan[1/58
(-11 Sqrt[58]+Sqrt[10382])]]-3/100
Cos[2 ArcTan[1/7 (-3+Sqrt[58])]] Sin[2 ArcTan[1/58
(-11 Sqrt[58]+Sqrt[10382])]]-7/100 Sin[2 ArcTan[1/7 (-3+Sqrt[58])]]
Sin[2 ArcTan[1/58 (-11 Sqrt[58]+Sqrt[10382])]]),
{b -> 2 ArcTan[1/7 (-3+Sqrt[58])],
a -> 2 ArcTan[1/58 (-11 Sqrt[58] + Sqrt[10382])]}}


where the coefficients are clearly related to the values of the denominators vx etc. as follows:

58 = 7^2 + 3^2
10382 = (7^2+3^2+11^2) * (7^2 +3^2)


Question Is it possible to perform the minimisation symbolically and if so, how? Can one declare vx etc. as Rationals directly or by assignment as the ratio of two Integers? I have tried including equivalent constraints within Minimize (one example given in code above), but to no effect.

I also tried defining a function accepting appropriate Integers and Reals, also without success.

f[a_Real, b_Real, c_Integer, d_Integer] :=
g (-vz Cos[a] - vy Cos[b] Sin[a] - vx Sin[b] Sin[a]);
vx = vy = vz = c/d;
Print["Minimize by defined function of integers = ",
Minimize[{f[a, b, c, d], 0 <= b < 2 Pi, 0 <= a < Pi}, {b, a},
Reals]];


I believe that the answer to this may also have a bearing on the use of Solve and simialr functions.

-
Thank you for the edits: I have noted what you did and will try to do likewise myself next time. Info on/links to info on how to do other than hyperlinks to documentation (e.g. grey background on variable names in text) would be welcome. –  Julian Moore Mar 27 '14 at 11:58
not sure why this old question got bumped, but if you solve the problem directly (with Reduce ) you'll see that the restriction on the parameters being rational doesn't enter into it,ie its a moot question. –  george2079 May 27 '14 at 18:30

## 1 Answer

It is very compute extreme-value problem in analysis.For example

Minimize[a x^2 + b x + c, x]


This this simple than your cases.It just have one extreme point If a！=0. But in your case, consider 0 <= b < 2 Pi, 0 <= a <2 Pi(the period of a and b is 2Pi, so we don't need consider boundary.Also we don't consider g).

Clear["Global*"]
t0[vx_, vy_, vz_] := -vz Cos[a] - vy Cos[b] Sin[a] - vx Sin[b] Sin[a];
ExtremePoint[vx_, vy_, vz_] :=
Select[Table[
Solve[{D[t0[vx, vy, vz], a] == 0, D[t0[vx, vy, vz], b] == 0}, {a,
b}][[All, All, 2]] /. {C[1] -> i, C[2] -> j}, {i, -1, 1, 1}, {j, -1, 1, 1}]
// Flatten[#, 2] &,
Function[{a, b}, (Not[NumericQ[a]] || 0 <= a <= 2 Pi) && (Not[NumericQ[b]] ||
0 <= b <= 2 Pi)] @@ # &]
ExtremePoint[1, 1, 1] // Length
ExtremePoint[vx, vy, vz] // Length


If vx=vy=vz=1,we just need consider 10 points.But if we don't know any about vx vy vz, we need consider 54 points ,and they all are symbolic expressions！

But there is a good thing that the values in extreme points is too simple.

t0[vx, vy, vz] /. {a -> #1, b -> #2} & @@@ ExtremePoint[vx, vy, vz]
//Simplify // DeleteDuplicates
(*{Sqrt[vx^2 + vy^2 + vz^2], -Sqrt[vx^2 + vy^2 + vz^2], -vz, vz}*)


So the minimize of function is

min[vx_, vy_, vz_] := -Sqrt[vx^2 + vy^2 + vz^2]


let us test it

testdata = RandomReal[{-10, 10}, {10, 3}]
min @@@ testdata
Minimize[{t0[##],0<=a<=Pi,0<=b<=2Pi}, {a, b}] & @@@ testdata
Minimize[{t0[##],0<=a<=2Pi,0<=b<=2Pi}, {a, b}] & @@@ testdata


It is just correct when we allow 0<=a<=2Pi because we don't consider the boundary(For example a=0)

Minimize[{t0[6.057, 0.972, 3.014], 0 < a < Pi}, {a, b}]


the position of extreme points is complex.

{t0[vx, vy, vz] /. {a -> #1, b -> #2}, {a->#1,a-> #2}} & @@@
ExtremePoint[vx, vy, vz]// Simplify // DeleteDuplicates;
Select[%, #[[1]] == -Sqrt[vx^2 + vy^2 + vz^2] &] // Length
`
-
Thanks... I will look at this in detail in the morning. In the meantime, just to mention that I also tried the derivative approach to extrema (with g) and maybe I was too impatient... I only allowed Mma about 10 minutes to solve. We shall see! Good food for thought. –  Julian Moore Mar 28 '14 at 17:18
I appreciate VERY much what you have done and I am learning a lot from it, but I was trying to understand how Minimize could work with numeric rationals and not symbolic rationals when numeric numerator and denominator elements seemed to propagate cleanly through Minimize. I did not mean to ask "how to minimise" in general, I mean "How to use Minimize" in this case. (and if it can't be used, to understand specifically why not, general complexity would be too non-specific an answer.) I would appreciate advice from anyone on whether to close this Q and re-ask or do something else –  Julian Moore Mar 30 '14 at 9:09