math

Math operations on arbitrary objects in C#

Hi, first question here, apologies in advance for any foul-ups. I'm implementing an interpreter for a toy language in C#, and in order to do math in that language I'd like to implement a function like this: public static object Add( object a, object b ) { // return the sum of a and b // each might be int, double, or one of many oth...

c++ large matrix inversion methods

Hi I've been doing some research about matrix inversion (linear algebra) and I wanned to use c++ template programming for the algorithm , what i found out that there are number of methods like: Gauss-Jordan Elimination or LU Decomposition and I found the function LU_factorize (c++ boost library) I want to know if there were other metho...

How do I efficiently find the maximum value in an array containing values of a smooth function?

I have a function that takes a floating point number and returns a floating point number. It can be assumed that if you were to graph the output of this function it would be 'n' shaped, ie. there would be a single maximum point, and no other points on the function with a zero slope. We also know that input value that yields this maximu...

convert from base 60 to base 10

I have a method that converts an int to a base60 string (using 0-9, a-z, and A-Z chars), but can't work out how to convert it back again. Here is my method for converting base10 to base60: public static function toBase60(value:Number):String { var targetBase:uint = 60; value = value.toString().split('.')[0]; var digits:Arra...

Speaking computer science in mathematicalese

I am in the process of writing a fairly long monograph on a computer science topic. However, I usually find myself in a position of having to write some computer science concept in mathematical terms, and it is difficult to me. For instance, say I want to write a for-loop or a void function. I do most of the time go to my Knuth or Cormen...

How to change 0.xxxx to xxxx in Java

Hi, As mentioned above. I give one example, let's say all the test values are less than 1 but greater than 0. 0.12 (precision: 3, scale:2) 0.345 (precision: 4, scale:3) 0.6789 (precision: 5, scale:4) how do i convert those value without hard-coding the scale and precision value. 0.12 -> 12 0.345 -> 345 0.6789 -> 6789 for 0.1 and...

Looking for an elegant and efficient C++ matrix library

Greetings, googling for that subject brings, e.g., MTL, exmat, LAPACK and also here. I also seem to remember that Microsoft Research released one, but can't put my hands on it. I look for advice from someone who actually used (or developed...) one of those, hoping to achieve a Matlab experience inside C++ (as much as possible). Thanks in...

Realistic page turn speed

I have written some page turning software simulating a magazine. Currently the speed of the page turning is linear, and I want to make it more realistic with acceleration and deceleration. At the start of the animation it should be slow, half way through it should have reached max speed, then it returns to a slow speed by the end of th...

Reverse a percentage

I have a percentage, it ranges from 50% to 0%. I need the values to be mirrored, so: 0% now equals 50% 1% = 49% 25% = 25% 48% = 2% 50% = 0% etc. Thanks for any help! ...

How-to: Find a good mathematical algorithm to distribute measuring points over time?

Hi folks. I'm currently implementing a software that measures certain values over time. The user may choose to measure the value 100 times over a duration of 28 days. (Just to give an example) Linear distribution is not a problem, but I am currently trying to get a logarithmical distribution of the points over the time span. The str...

Find combinations of numbers that sum to some desired number

I need an algorithm that identifies all possible combinations of a set of numbers that sum to some other number. For example, given the set {2,3,4,7}, I need to know all possible subsets that sum to x. If x == 12, the answer is {2,3,7}; if x ==7 the answer is {{3,4},{7}} (ie, two possible answers); and if x==8 there is no answer. Note t...

Calculating the angle between two lines without having to calculate the slope? (Java)

Hi, I have two Lines: L1 and L2. I want to calculate the angle between the two lines. L1 has points: {(x1, y1), (x2, y2)} and L2 has points: {(x3, y3), (x4, y4)}. How can I calculate the angle formed between these two lines, without having to calculate the slopes? The problem I am currently having is that sometimes I have horizontal lin...

Math: Ease In, ease Out a displacement using Hermite curve with time constraint

Hi, I'm trying to write a method that interpolates from 0 to x (position of an object in one dimension) over time using acceleration at the beginning and deceleration at the end (ease out / ease in) with the only constraints that the total time is provided, as well as the duration of the acceleration and deceleration. the motion should r...

Evenly distributing all items in a list.

Hi, I have had this problem for a while, still trying to work on a solution. What is the best possible method for evenly distributing items in a list, with a low discrepancy? Say we have a list or elements in an array: Red, Red, Red, Red, Red, Blue, Blue, Blue, Green, Green, Green, Yellow So ideally the output would produce someth...

php convert floating point to long (convert to string to pass to a xml function)

Hi, PHP converts a large number to floating point which I need in "long" format to pass to a soap xml api. ((round(time()/(60*15))*60*15)+(30*60))*1000 This gives the result: 1.28E+12 Whereas, what I need is: "1280495700000" in order to pass to the api ...

Efficient way to find explanations of a method-test-matrix (mathematical problem)

Setup: I have a boolean matrix e.g. 1 0 1 1 0 1 where rows are named m1, m2, m3 (as methods) and columns t1 and t2 (as tests). Definition: An explanation is a set of rows (methods) which in union have at least one "1" in any column (every test hast to be matched by at least one method). in our example, the set of explanations ...

Convert Lat/Lon to MGRS

Does anyone know where I could find a library of code for converting Lat/Lon position to Military Grid Reference System (MGRS)? I'm looking for a C# implementation if possible. ...

Methods to convert mathematical formulas into code in Matlab, C++, etc?

Hi, I have a basic question for all of the math experts out there. "If I have an academic paper, whats the easiest way to convert a simple mathematical equation into working Matlab (or C++) code?" Ideally, there would be a Latex >> Matlab (or C++) conversion tool. However, failing this, is there a "cheat sheet" which contains all of ...

Calculation to get page count based on # of items

If I have 177 items, and each page has 10 items that means I'll have 18 pages. I'm new to python and having used any of the math related functions. How can I calculate 177/10 and then get round up so I get 18 and not 17.7 ...

Asp.net C# math problem

I'm trying to build a "simple" web app that calculates either a male or females body fat % based on the U.S. Navy's circumference formula. I have the majority of the app completed at this point. However, I cannot figure out why the way I've setup the formula below won't work. Two of the values are underlined in red in my .cs file. My...