math

Javas Math.sin() produces NaN all the time

Forgive me if this is a dumb beginners problem, but I really don't get it. I have a member variable declared like so: public Double Value; When I assign 3.14159265 to Value and try to compute the sine of it, this happens: system.out.println(Value.toString()); //outputs 3.14159265 Value = Math.sin(Value); system.out.println(Value.toS...

Need help with C# function to translate smoothly between numeric ranges

I'm trying to write a function : Input: Source range, Source value, output range, curve type (Linear, smooth) Output: The output is the "source value" converted into the "output range" according to the curve type. I hope I am making sense here... Any ideas ? Thanks. ...

How to determine the modulus of a Float in Ada 95

I need to determine the amount left of a time cycle. To do that in C I would use fmod. But in ada I can find no reference to a similar function. It needs to be accurate and it needs to return a float for precision. So how do I determine the modulus of a Float in Ada 95? elapsed := time_taken mod 10.348; left := 10.348 - elapsed; del...

PHP time math calculations

Hallo, How can I calculate a current time moment + exactly one week? The same with month. Thanks. ...

optimized grid for rectangular items

I have N rectangular items with an aspect ratio Aitem (X:Y). I have a rectangular display area with an aspect ratio Aview The items should be arranged in a table-like layout (i.e. r rows, c columns). what is the ideal grid rows x columns, so that individual items are largest? (rows * colums >= N, of course - i.e. there may be "unused" ...

How to calculate the cycles that change one permutation into another?

Hi, I'm looking for an algorithm that given two permutations of a sequence (e.g. [2, 3, 1, 4] and [4, 1, 3, 2]) calculates the cycles that are needed to convert the first into the second (for the example, [[0, 3], [1, 2]]). The link from mathworld says that Mathematica's ToCycle function does that, but sadly I don't have any Mathematica...

correcting fisheye distortion programmatically

BOUNTY STATUS UPDATE: I discovered how to map a linear lens, from destination coordinates to source coordinates. I actually struggle to reverse it, and to map source coordinates to destination coordinates. What is the inverse, in code in the style of the converting functions I posted? I also see that my undistortion is imperfect ...

Ruby: Change negative number to positive number?

What's the simplest way of changing a negative number to positive with ruby? ie. Change "-300" to "300" ...

Use Math class to calculate

Write a JAVA program that calculates the surface area of a cylinder, C= 2( π r2) + 2 π r h, where r is the radius and h is the height of the cylinder. Allow the user to enter in a radius and a height. Format the output to three decimal places. Use the constant PI and the method pow() from the Math class. This is what I've done so far bu...

Examples of monoids/semigroups in programming

It is well-known that monoids are stunningly ubiquitous in programing. They are so ubiquitous and so useful that I, as a 'hobby project', am working on a system that is completely based on their properties (distributed data aggregation). To make the system useful I need useful monoids :) I already know of these: Numeric or matrix sum ...

Calculating negative fractions in Objective C

I've been coding my way through Steve Kochan's Programming in Objective-C 2.0 book. I'm up to an exercise in chapter 7, ex 4, in case anyone has the book. The question posed by the exercise it will the Fraction class written work with negative fractions such as -1/2 + -2/3? Here's the implementation code in question - @implementation ...

Trouble with javascript subtraction

I'm working on a simple subtraction problem, but unfortunately it keeps returning NaN Here is the function function subtraction(a, b) { var regexp = /[$][,]/g; a = a.replace(regexp, ""); b = b.replace(regexp, ""); var _a = parseFloat(a); var _b = parseFloat(b); return _a - _b; ...

How could I check if a number is a perfect square?

I'm pretty stumped with this one guys. I'm trying to toy with Python (as you can see with my previous questions) so I'd really love some help here. :P Speeds is of no concern for now, just working. Thanks! Edit: I ended up doing it this way: def isSquare(number): temp = math.sqrt(int(number)) if "." in str(abs(int(temp))...

C++ : Math library that solve system of equations using back substitution algorithm

If I have this: A * f = g; A: upper triangular matrix (n x n) f: (n x 1) g: (n x 1) Need to solve for f using back substitution algorithm. I would say that it not really that hard to write one myself, but oh well, if there is a library out there, then why not. ...

Calculate proportional width of object (proportion: 1600x1080)

Hello, this is a simple jquery question: when my div "#wrapper" has a specific height (=browser height - 129px), i want to set the width of a inner div "#object" automatically too (cause i need a width for the object to read it out) ° example of the html: <div id="wrapper"> <div id="object"> </div> </div> example (jquery): $(...

Interpolating height for a point inside a grid based on a discrete height function.

Hi, I have been wracking my brain to come up with a solution to this problem. I have a lookup table that returns height values for various points (x,z) on the grid. For instance I can calculate the height at A, B, C and D in Figure 1. However, I am looking for a way to interpolate the height at P (which has a known (x,z)). The lookup...

Stupid problem with Javascript calculations and postbacks

I'm working on an ASP.NET web app where I'm using a Wizard to take the client through a large series of steps. One of the steps includes calculating a bunch of numbers on the fly... the numbers calculate properly but when I click "next" and then go back again... some of the numbers are not retained. Here is the calculation function fu...

Javascript: Add +1 to number that starts with 0 (like 01, 02, 03) and keep the zero

Hi, I like to add (+1) to a number. But problem is my number can sometimes have 0 preceding it. Like 01, 02, 03, 04. So I like result to be: mockup01 + 1 = mockup02 mockup11 + 1 = mockup12 How can that be achieved? Example of how I would use it would be if I had filename named mockup_01.htm and change it to mockup_02.htm Thanks! ...

Calculating rotation in > 360 deg. situations

I'm trying to work out a problem I'm having with degrees. I have data that is a list of of angles, in standard degree notation -- e.g. 26 deg. Usually when dealing with angles, if an angle exceeds 360 deg then the angle continues around and effectively "resets" -- i.e. the angle "starts again", e.g. 357 deg, 358 deg, 359 deg, 0 deg, 1 ...

Howto project a planar polygon on a plane in 3d-space

I want to project my Polygon along a vector to a plane in 3d Space. I would preferably use a single transformation matrix to do this, but I don't know how to build a matrix of this kind. Given the plane's parameters (ax+by+cz+d), the world coordinates of my Polygon. As stated in the the headline, all vertices of my polygon lie in an...