Solving Trignometric Transcedental equations in Matlab

574 Views Asked by At

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.

1

There are 1 best solutions below

3
On

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 solve is 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 fsolve command 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:

alpha = some constant value;
psi = some other constant value;
two_alpha = 2*alpha;
two_psi = 2*psi;
phi_r0 = some guess;
delta_r0 = some other guess;
x0 = [phi_r0; delta_r0]; % x(1) is phi_r, x(2) is delta_r
f = @(x)[tan(2*x(1))*cos(x(2))-tan(two_alpha); sin(2*x(1))*sin(x(2))-sin(two_psi);
[x,fval] = fsolve(f,x0);

Picking the initial guesses for $\phi_r$ and $\delta_r$ is left to you.