I need a little help solving these eqns using Matlab. phir and delr values are required. alpha and psi are constants.
[phir,delr]=solve(tan(2*phir)*cos(delr)-tan(2*alpha) , sin(2*phir)*sin(delr)-sin(2*psi));
Thanks a lot in advance.
I need a little help solving these eqns using Matlab. phir and delr values are required. alpha and psi are constants.
[phir,delr]=solve(tan(2*phir)*cos(delr)-tan(2*alpha) , sin(2*phir)*sin(delr)-sin(2*psi));
Thanks a lot in advance.
Copyright © 2021 JogjaFile Inc.
In general, you have two methods of solving equations: symbolically and numerically. If you're going to solve numerically, you need to know whether your equations are linear or nonlinear (yours are nonlinear). Next, you need to determine if their gradient is well-defined and/or easy to compute. Depending on the algorithm, you might need to compute the gradient by hand. If this is too difficult, there are a bevy of options for handling this difficulty. However, I do not intend to present a treatise on numerical analysis.
The MATLAB command
solveis part of the symbolic toolbox. Since you have not presented any other code, I do not know whether you have properly set up a symbolic solution, and since I think the symbolic toolbox, ultimately, is a waste, I will ignore it.Instead, you have the system of equations:
$$\begin{align*}\tan 2\phi_r \cos \delta_r &= \tan 2\alpha, \\ \sin 2\phi_r \sin\delta_r &= \sin 2\psi\end{align*}.$$ I presume $\alpha$ is a constant.
Define functions $$\begin{align*} \mathbf{f}(\phi_r,\delta_r) &\stackrel{\textrm{def}}{=} \begin{pmatrix} f_1\left(\phi_r,\delta_r\right), \\ f_2\left(\phi_r,\delta_r\right)\end{pmatrix} \\ f_1(\phi_r,\delta_r) &\stackrel{\textrm{def}}{=} \tan 2\phi_r \cos \delta_r - \tan 2\alpha, \\ f_2(\phi_r,\delta_r) &\stackrel{\textrm{def}}{=} \sin 2\phi_r \sin \delta_r - \sin 2\psi, \end{align*}$$ and your system becomes
$$\mathbf{f}(\phi_r,\delta_r) = \mathbf{0}.$$
Using the Optimization Toolbox, we can use the
fsolvecommand to solve equations of this form, provide we have an initial guess. Let this initial guess be $\mathbf{x}_0 = \begin{pmatrix} \phi_{r_0} \\ \delta_{r_0}\end{pmatrix}$.Our code would then be:
Picking the initial guesses for $\phi_r$ and $\delta_r$ is left to you.