1
$\begingroup$

At the moment I am programming software which uses the math function below to do its job. The key about this is that I cannot assume values for the coefficients found in the function since they are not known until the software is running (or rather the part of it that is executed before the function should be solved).

My kind of math function: $f(x) = -A * sin(x) * sin(Z) + B * cos(x) * cos(Z) - C + D$

My current understanding is that for this type of mathematical function I will have to use a numerical root-finding algorithm (e.g. Regula Falsi) to get the value x for the set of constants in the function.

I am using third-party software to use root-finding software and most of the methods available require a given interval in which the solution is searched, with the exception of the Newton-Raphson method. I know that the correct values for my x must be between [0, 2*PI]. However, the key problem is that I cannot use this interval every time, because for one set of coefficients the mathematical condition (for the root-finding methods) of different signs for f(lower boundary) and f(upper boundary) is satisfied and for other coefficients it might not be. And when the signs are not different for f(l. boundary) and f(u. boundary) the root-finding method results in a programmatic error and my software fails.

Whenever I used numerical root-finding algorithms in school I manually chose fitting interval boundaries after looking at the function (with known coefficients) visually. Obviously and unfortunately I cannot do that in this use case.

What I need now is advice on solving this kind of function with the level of unknown constants (until software runtime) found in this function.

I would be very thankful for any kind of advice!

$\endgroup$
3
  • $\begingroup$ Could you be clearer about what you mean with "unknown/dynamic"? Does this mean that your function is like a black box: you can feed it an input and get an output, but you don't know anything about its internal workings besides that it does what function $f$ does with some unknown parameters $A,B,C,D$? Does it mean that on every use of the function the values change? $\endgroup$ Jan 9, 2017 at 12:21
  • $\begingroup$ Dynamic shall mean that $ABCDZ$ are never known by the program until it finally executes. The user of the application has the ability to specify these. But then after he specified these, a different $x$ gives a different result of the equation. $\endgroup$
    – typo
    Jan 12, 2017 at 15:56
  • $\begingroup$ So, user specified really. Then LutzL's reply is definitely the way to go. $\endgroup$ Jan 12, 2017 at 20:32

1 Answer 1

1
$\begingroup$

Let $(R,\phi)$ be the polar coordinates of the point $(B\cos(Z),A\sin(Z))$. Then your equation reduces by trigonometric identities to $$ R\cos(x+\phi)=C-D. $$ This equation is now easy to solve, there is no solution in the case $|C-D|>R$, and if $|C-D|\le R$, then $$ x=-\phi\pm\arccos\frac{C-D}R $$ and their $2\pi$ periodic repetitions provide an infinity of solutions.

$\endgroup$
8
  • $\begingroup$ Why do you treat the terms of $B*cos(Z) + A*sin(Z)$ as coordinates of a point (and what point is that)? I don't understand the math theory behind it. $\endgroup$
    – typo
    Jan 4, 2017 at 20:45
  • $\begingroup$ You have to solve $R\cosϕ=B\cos(Z)$, $R\sinϕ=A\sin(Z)$, in code this could be done by R=hypot(A*sin(Z),B*cos(Z)), phi=atan2(A*sin(Z),B*cos(Z)). Then use that $\cos(x+ϕ)=\cos x\cos ϕ-\sin x\sin ϕ$. $\endgroup$ Jan 4, 2017 at 23:35
  • $\begingroup$ I still do not understand what kind of point you are referring to when you say "Let $(R, ϕ)$ be the polar coordinates of the point $(B*cos(Z), A*sin(Z))$". It's hard for me to use advice when I do not follow. A,B,C,D and Z by the way are simple numbers and not vectors, therefore the result of the function f(x) is also a number. $\endgroup$
    – typo
    Jan 9, 2017 at 9:01
  • $\begingroup$ Any non-zero point in the Cartesian/Euclidean plane has polar coordinates. Any pair of real numbers can be interpreted as a point in the Cartesian plane. $\endgroup$ Jan 9, 2017 at 9:25
  • $\begingroup$ Did you treat the signs of C and D exactly like the equation of my initial question? Or have you applied the principle that $-C = C$ because it is a constant anyway? Because for my use case I often seem to reach $|C−D|>R$ and therefore get no real result with your proposed soultion. Also I had a sign error in my initial equation, because it actually is $f(x)=B∗cos(x)∗cos(Z)-A∗sin(x)∗sin(Z)−C+D$ (note the negative sign). Would that change your proposed equation or the limits? $\endgroup$
    – typo
    Jan 12, 2017 at 15:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .