i am using haversine formula in java programming (using eclipse).
My problem is at the end of the equation where i get an error (atan is underlined) saying that "The method atan(double) is undefined for the type Math".
i dont know what is the problem. Does anyone have an idea?
double angle = 45;
double arctan = Math.atan(angle);
Do you have any other Math class in the same package? Maybe you could try:
double angle = 45;
double arctan = java.lang.Math.atan(angle);
The only possible reason that I can think of for why this might happen is that there is a namespace conflict. That is to say that the compiler thinks the Math in your method is referencing some other Class called Math instead of java.lang.Math
In eclipse if you hover your mouse cursor over Math it will bring up a context window showing you what package it thinks Math belongs to. If it's not java.lang then that's your problem.
Are you programming mobile application and using Java ME? In that case the Math library really doesn't contains atan function. So you have to calculate atan by yourself. This topic was discussed here and also here.
Related
I have been working on a mathematical model for 3 months. I have a constraint like this:
Where x and y are decision variables, p is a parameter.
I wrote my mathematical model using Java, I tried a lot of things but all of them doesn’t work correctly or gives error.
Would you please help me?
I need help calculating the angle between the 5 and the 3. I have absolutely no idea how to even model the question, let alone convert it to java. This is entirely specific, does not need to be abstracted.
int a=3; int b=4; int c=5;
is honestly as far as I can get. This would be cos(b), right? I just need a quick pointer/solution
Is this a right-triangle? So the 5 is the hypotenuse (the side opposite the right angle)?
If that's the case, you need to find any one of the following (which should all be equal to each other): arctan(4/3), ArcSin(4/5), or arccos(3/5).
For example, using the first:
Math.toDegrees(Math.atan(4.0/3.0))
I've got a matrix of values like the one below that I need to scale. I've been looking around for an inbuilt function if there is one that could do this for me. I haven't found one & so have ended up writing code to do the scaling using the below formula
scaledMatrix = (Matrix - MeanMatrix)/Standard Deviation
This code is a bit buggy & I'm working on correcting it. While I do that, I happened to bump on java.math.BigDecimal.scale() & did look up an equivalent for double as the matrix I have is double type numbers
If someone could please help me with details on
1) If there is an inbuilt function that accepts matrix of values & returns me the scaled matrix
2) `java.math.BigDecimal.scale()` equivalent for `double` type data
Any help would be much appreciated please.
The BigDecimal.scale() method does not do what you seem to think it is doing. A BigDecimal value is stored as a * 10^b (where ^ denotes exponentiation). The BigDecimal.scale() method basically returns the b part of that.
I do not know of a similar method for double values, nor do I know of a method which performs the function you need. Since you put apache-commons in the tags, I suggest you look into Apache Commons's extensive statistical library.
I need some help with a formula or bit of code for finding the distance to the closest point in a line segment. Effectively, the "distance from the line segment" is going to be used as a sort of "bonding box", so that a user can click relatively close to a line, and it count as clicking on that line.
If you're using Swing, then you should be able to use Line2D.ptSegDist(Point2D) or its various overloads to do all the math for you.
This page explains how to find the closest point on a line.
It also includes a sample implementation in Java.
Java function
public static
double
distanceToSegment( final R3 v, final R3 a, final R3 b )
full gist:
https://gist.github.com/anonymous/6ca967360b5a6613604c416fe50d2d87
from open source library
https://sourceforge.net/projects/geokarambola/
I just started using Java to simulate solar panel's performance, however the single diode model requires lots of calculations:
basically, each function is a function of the other, all of them of the variable of Rs, a.
two equations are available from f, f1.
how can i get the value of Rs, a.
I can extract Rs, a from the equations and take it to the equation of f, f1.
however, the equation will be of great difficulty to solve, as it has exp(), multi-times of the variable and ln()..
is there any library to use to calculate the value of variables by given constraint?
the equations are basically like this:
v = 3.5a
ff0= 5/v+ln(5/v+0.7)/(5/v+1)
ffs = ff0*(1-Rs*1.1)+(Rs*8)^2
....
...
..
f: 9=constant1-ffs*((exp(v-4/Rs))-1)-(15+8*Rs)*a
f1: 9=15*(ffs*.....)
thank you.
You haven't concisely characterized the kind of equations that you want to solve, but the examples look rather hairy. If they are solvable (symbolically) then a commercial package like Mathematica is probably a good bet.
But I think you'd probably be better off asking this kind of question on the
http://math.stackexchange.com/
where real mathematicians hang out. If nothing else they can characterize your equations for you and tell you if they are likely to be solvable.