# java trigonometric solver

Discussion in 'Java' started by Guntius.GIBLI, Sep 7, 2006.

1. ### Guntius.GIBLIGuest

Hi all,
I'm trying to implement in Java a solver for this kind of
trigonometric system...

k * sin( a1 * f ) = b1
k * sin( a2 * f ) = b2

my job is to find "f" whenever is possible.

GG

Guntius.GIBLI, Sep 7, 2006

2. ### M.J. DanceGuest

M.J. Dance, Sep 7, 2006

3. ### Guntius.GIBLIGuest

yeah of course
I was meaning a value for "f" not really "f" itself!!!

GG

Guntius.GIBLI, Sep 7, 2006
4. ### M.J. DanceGuest

Oh! Well, in that case, you know, of course, that life's complex, don't you? It
has both real and imaginary components. So, do you mind telling us moe about
your k, a1, a2, f, b1 and b2? Are they really ;-) nasty? Or 'merely' complex?
Functions even? What kind of functions? Whatever they may be, however, I don't
think that the solution is Java dependent.

M.J. Dance, Sep 7, 2006
5. ### Guntius.GIBLIGuest

k is calculated in order to force
-1 <= ai/k <= 1 for every i
-1 <= bi/k <= 1 for every i

ai and bi are integers (I mean they are stored in java integers)
in general ai != aj for every i != j and
the same condition should be verified for bi ...
so they seems not to be nasty nor complex...

The solution I'm looking for is a java one, if eventually someone
otherwise I have to implement it in java ... thus I need some help.

on condition -1 <= a <= 1
that is absolutely my case.

it seems the solution to be:
x = alpha + 2 k pi
x = pi - alpha + 2 k pi

but since I have
x = ai * f
and
alpha = bi / k
I get:
f = (bi / k + 2 k pi) / ai
f = pi - (bi / k + 2 k pi) / ai

that it is not exacly what I was expecting... so I am a little bit
stuck!!!

GG

Guntius.GIBLI, Sep 7, 2006
6. ### Peter Van WeertGuest

solvers, algorithms, ... They will now better whether suited
implementations exists (maybe even in Java, but I doubt it), or how to
implement it yourself in Java. I would first look for existing solvers
and let them do the hard work, even if this is outside our beloved Java.

Cheers,
Peter

Peter Van Weert, Sep 7, 2006
7. ### M.J. DanceGuest

You mean for both of them. ;-) But really, sin(x) \in [-1, 1]? Wow! ;-)
Hey, Gunitus, how much do you know about trigonometry? Or math for that matter?
Specifically... forget the solution for a moment: do you understand the problem
(t.i. "question")?
Here you go! All you have to do now is translate these two lines into Java.
What _were_ you expecting? Just curious...

M.J. Dance, Sep 7, 2006
8. ### Patricia ShanahanGuest

The only really Java-specific information that seems relevant to the
problem is that Math.asin(x) returns an angle, in radians, whose sine is
x. See the API documentation for details.

Patricia

Patricia Shanahan, Sep 7, 2006
9. ### Guntius.GIBLIGuest

I was expecting a
single function capable of giving me all values of "f"
and not two distinct functions...
GG

Guntius.GIBLI, Sep 7, 2006
10. ### Guntius.GIBLIGuest

Well anyway I don't really understand the problem...
and I'm not very well suited in math ...

the fact is that I should deliver this function as a small part of a
bigger project
I'm not allowed to know about?!
weird thing I know but the fact is that I only know the input, the
output and the CPU time I have to do the trick...

oooh yes and I have to do the whole thing in a nice java function...

thanks you very much anyway
you really helped me.
GG

Guntius.GIBLI, Sep 7, 2006
11. ### Guntius.GIBLIGuest

Thanks you very much... it seems that an approach could be:

fi =Math.asin(bi/A)/ai
fi =pi - Math.asin(bi/A)/ai

at this point I have just to solve the system and find the only
possible values for "fi"...

well I hope it will work I'll keep you post it,
just in case you are interested in any positive result.
GG

Guntius.GIBLI, Sep 7, 2006
12. ### Dale KingGuest

It seems to me that there is an infinite number of values for fi, if I
understand the problem correctly (and your explanation so far has not been
very clear).

Dale King, Sep 8, 2006
13. ### M.J. DanceGuest

I can't help you if I don't know (exactly) what the problem is. As you obviously

And of course, there's the proverbial Usenet reluctance of doing someone elses
homework. In order to get help, the least you should do is show some effort of
trying to solve the problem yourself.

Now, as you found out in another post, your f = f(ai, bj, k). A few additional
conditions (ai and bi being integers and so on) puts a few additional

Oh, and, "translating" that into Java is the least of your problems.

M.J. Dance, Sep 8, 2006
14. ### Patricia ShanahanGuest

Don't forget that any pair of angles separated by 2*pi radians have the
same sine.

Patricia

Patricia Shanahan, Sep 8, 2006