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!

  • 0
    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?2017-01-09
  • 0
    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.2017-01-12
  • 0
    So, user specified really. Then LutzL's reply is definitely the way to go.2017-01-12

1 Answers 1

1

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.

  • 0
    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.2017-01-04
  • 0
    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 ϕ$.2017-01-04
  • 0
    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.2017-01-09
  • 0
    Any non-zero point in the Cartesian/Euclidean plane has [polar coordinates](https://en.wikipedia.org/wiki/Polar_coordinate_system). Any pair of real numbers can be interpreted as a point in the Cartesian plane.2017-01-09
  • 0
    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?2017-01-12
  • 0
    No, I used $-C+D=-(C-D)$. Changed the sign of $ϕ$ back. Apart from the sign change, the solution analysis does not change.2017-01-12
  • 0
    Thanks for responding to my updated question. However, I'm in trouble since $| C - D | > R$ is easily possible for my input, therefore in most cases I do not receive a real value for the $\arccos\frac{C-D}R$ part.2017-01-17
  • 0
    In that case, the graph of $f$ is an oscillation that never crosses the $x$ axis. Why do you expect the problem to be solvable?2017-01-17