如何在 Mathematica 中最小化具有约束的函数

How to minimize a function with constraints in Mathematica

我想最小化以下函数:

Ef[J2_, D2_, θA1_, θC1_, \[Phi]A1_, \[Phi]C1_] := 
  J2 (Sin[θA1] Sin[θC1] (Cos[\[Phi]A1] Cos[\[Phi]C1] + 
         Sin[\[Phi]A1] Sin[\[Phi]C1]) + Cos[θA1] Cos[θC1]) - 
   D2 (Sin[θA1] Cos[\[Phi]A1] Cos[θC1] - 
      Cos[θA1] Sin[θC1] Cos[\[Phi]C1]);

例如 J2=0.1;D2=0.1;,其中 0<= theta <= pi 和 0<=phi<=2 pi 我试过了

Minimize[{Ef[J2, D2, θA1, θC1, \[Phi]A1, \[Phi]C1], 
{θA1 \[Epsilon][0, π], θC1 \[Epsilon][0, π], \[Phi]A1 \[Epsilon][0, 2 π], \[Phi]C1 \[Epsilon][0, 2 π], }}, {θA1, θC1, \[Phi]A1, \[Phi]C1}]

但我的输入得到了重印...

有什么建议吗?

谢谢, M

我打算尝试不同的方法,看看是否能找到解决方案

Ef[J2_, D2_, θA1_, θC1_, φA1_, φC1_] :=  J2 (Sin[θA1] Sin[θC1]*
  (Cos[φA1] Cos[φC1] + Sin[φA1] Sin[φC1]) + Cos[θA1] Cos[θC1]) -
  D2 (Sin[θA1] Cos[φA1] Cos[θC1] - Cos[θA1] Sin[θC1] Cos[φC1]);
J2=1/10;D2=1/10;
NMinimize[{Ef[J2, D2, θA1, θC1, φA1, φC1], 0<=θA1<=Pi&&0<=θC1<=Pi&&
  0<=φA1<=2 Pi&&0<=φC1<=2 Pi}, {θA1, θC1, φA1, φC1},WorkingPrecision->32]

立即给了我

{-0.1414213562373095048801688724209560058569711627807200358098`32., 
 {θA1 -> 1.3609367058891979125401402005460735210021598955174397243367`32., 
  θC1 -> 2.5660541110980434566496343521125515860033321979399030055079`32., 
  φA1 -> 3.1415926535897927498306628362843651999778557816889010918926`32., 
  φC1 -> 6.2831853071795854493988148705854136770428612595496860217646`32.}}

我注意到 φA1 几乎肯定是 Pi 而 φC1 几乎肯定是 2 Pi 所以

s=Simplify[Ef[J2, D2, θA1, θC1, φA1, φC1]/.{φA1->Pi,φC1->2 Pi}]

给予

(Cos[θA1 + θC1] + Sin[θA1 + θC1])/10

现在我想找到解决办法

FullSimplify[Minimize[{s, 0<=θA1<=Pi&&0<=θC1<=Pi}, {θA1, θC1}]]

给予

{-1/(5*Sqrt[2]), {θA1 -> Pi, θC1 -> Pi/4}}

仔细检查以确保没有错误。

看看有多少个 -Sqrt[2]/10 的局部最小值满足你的约束条件

Length[Select[Partition[Flatten[Table[
  {Ef[J2, D2, θA1, θC1, φA1, φC1], θA1, θC1, φA1, φC1},
  {θA1,0,Pi,Pi/4},{θC1,0,Pi,Pi/4},{φA1,0,2Pi,Pi/64},{φC1,0,2 Pi,Pi/64}]],
  5],#[[1]]==-Sqrt[2]/10&]]

可能还有更多。