Please help me in finding matlab code

58 Views Asked by At

How do I find the max value and the unknown variables of $$f=-\cos(\theta_A)\cos​(\theta_B)-​\sin(\theta_A)\sin(\theta_B)\sin(\phi_A)\sin(\phi_B)​-\cos(\phi_A​)\cos(\phi​_B)\sin(\theta_A)\sin(\theta_B​)$$ in matlab.

Where $\theta_A, \theta_B, \phi_A, \phi_B$ are unknown variables. Please tell me how to put the code.

1

There are 1 best solutions below

0
On

This is not really a job for Matlab.

Let $$s = \sin(\phi_A) \sin(\phi_B) + \cos(\phi_A)\cos(\phi_B) = \cos(\phi_A - \phi_B)$$ This can be anywhere from $-1$ to $+1$ (assuming you want your variables to be real). Then $$f = -\cos(\theta_A)\cos(\theta_B) - s \sin(\theta_A)\sin(\theta_B) = \dfrac{1-s}{2} \cos(\theta_A +\theta_B) - \dfrac{1+s}{2} \cos(\theta_A - \theta_B) = \lambda \cos(\theta_A + \theta_B) - (1-\lambda) \cos(\theta_A - \theta_B)$$ Since $-1 \le s \le 1$, $0 \le \lambda = (1-s)/2 \le 1$. Thus $f$ can be anywhere from $\cos(\theta_A + \theta_B)$ to $-\cos(\theta_A-\theta_B)$, and so again from $-1$ to $1$.

To get the maximum value of $1$, you have three alternatives:

  1. $\cos(\theta_A + \theta_B) = 1$ and $\cos(\theta_A - \theta_B) = -1$ (e.g. with $\theta_A = \pi/2$ and $\theta_B = -\pi/2$); $\phi_A$ and $\phi_B$ can be anything.
  2. $\cos(\theta_A + \theta_B) = 1$ and $\lambda = 1$, so $s = \cos(\phi_A - \phi_B) = -1$. Thus you could have $\theta_B = -\theta_A$ and $\phi_B = \pi + \phi_A$ for any $\theta_A$ and $\phi_A$.
  3. $\cos(\theta_A - \theta_B) = -1$ and $\lambda = 0$, so $s = 1$. Thus you could have $\theta_B = \pi + \theta_A$ and $\phi_B = \phi_A$ for any $\theta_A$ and $\phi_A$.