math

Evaluating a mathematical expression in a string

stringExp = "2^4" intVal = int(stringExp) # Expected value: 16 This returns the following error: Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: invalid literal for int() with base 10: '2^4' I know that eval can work around this, but isn't there a better and - more importantly - safer method...

Why does ceiling in .NET return a Double and not an integer?

As explained here, Math.Ceiling returns: "The smallest integral value that is greater than or equal to a". But later it says: "Note that this method returns a Double type instead of an integral type." I'm just wondering why? ...

How can you calculate the X/Y coordinate to zoom to

Im writing a WPF application that has a zoom and pan ability, but what I want to also implement is the ability to zoom and pan "automatically" (via a button click). I have the methods all defined to zoom and pan, but Im having trouble telling the app the desired X/Y coordinates for the panning. Basically, I know that I want the control...

Python and a "time value of money" problem.

(I asked this question earlier today, but I did a poor job of explaining myself. Let me try again) I have a client who is an industrial maintenance company. They sell service agreements that are prepaid 20 hour blocks of a technician's time. Some of their larger customers might burn through that agreement in two weeks while customers w...

Rendering mathematical notation in Python / OpenGL ?

How can I render mathematical notations / expressions in Python with OpenGL? I'm actually using pyglet however it uses OpenGL. Such things as this: I can't store static images as I am generating the expressions as well. ...

Combined average for priority and due date

Assume that a task exists with two attributes: priority and due date. Priority p is a numeric value. The priority importance increases to infinity, meaning that 5 is a priority higher than 4. Priority 0 is normal priority. Due date d is a date in the past or in the future, when compared with the current date. A d date before now is mor...

What does x.length do in JavaScript?

I am doing this JavaScript math question where it asks me his math question. I do the math, type the answer in the box, and sumbit it. If i am right I move on but I got lost at x.length. I don't know what that means. Here is a example of the problem: var a= 5+6*4 var b= a / 9 Function (x) ( if (x.length == b) ...

Can we find out the difference between 2 RGb colors to find out a 3rd color?

2 colors are mixed together. If i have the RGB for the resultant color and RGB for one of the colors mixed, then somehow i could calculate the 2nd color? I will try to explain visually what i am trying to say. Here is a flickr link http://www.flickr.com/photos/48150615@N08/4407414157 I know that the circle in the middle has an opacity...

How would you calculate all possible permutations of 0 through N iteratively?

I need to calculate permutations iteratively. The method signature looks like: int[][] permute(int n) For n = 3 for example, the return value would be: [[0,1,2], [0,2,1], [1,0,2], [1,2,0], [2,0,1], [2,1,0]] How would you go about doing this iteratively in the most efficient way possible? I can do this recursively, but I'm int...

Encoding / Error Correction Challenge

Is it mathematically feasible to encode and initial 4 byte message into 8 bytes and if one of the 8 bytes is completely dropped and another is wrong to reconstruct the initial 4 byte message? There would be no way to retransmit nor would the location of the dropped byte be known. If one uses Reed Solomon error correction with 4 "parity...

code to "finish off a graph"

I want to graph from one date to another date and i only partial data now For example, i have data points for each month from jan 2010 to march 2010 but i want a line graph with a data point for each month for all of 2010. i basically want to take the slope of the current points and create new points for each future month of 2010 to fi...

When zooming an image how can I determine a proper w/h so that I won't get decimals

Hi, Lets say I have a non-square image.. If I increment the width and I recalculate the height according to the incremented width (ratio), sometimes I get xxx.5 (decimals) for the width ex.: width = 4, height = 2 I augment the width with a factor of 1.25 I'll get : width = 5 Next, the height will be : heigth = 2.5 How can I determine...

Round a divided number in Linux

How would I round the result from two divided numbers, e.g. 3/2 As when I do testOne=$((3/2)) $testOne contains "1" when it should have rounded up to "2" as the answer from 3/2=1.5 ...

Are there any C# math libraries that do interpolation / extrapolation

For example, I have points Y X 100 50 90 43 80 32 need to solve for y = 50 or Y X 1/1/2009 100 1/3/2009 97 1/4/2009 94 1/5/2009 92 1/6/2009 91 1/7/2009 89 need to solve for y = 1/23/2009 ...

Plot Equations using Javascript (or anything client side)

Is there any library which I can use to plot mathematical equations? (Preferably using javascript, could me in Java also; or anything clientside) ...

Detecting Singularities in a Graph

I am creating a graphing calculator in Java as a project for my programming class. There are two main components to this calculator: the graph itself, which draws the line(s), and the equation evaluator, which takes in an equation as a String and... well, evaluates it. To create the line, I create a Path2D.Double instance, and loop thro...

iPhone visualizing math pattern

Hi, I'm toying with an app idea for the iPhone but I don't know where to start or even what to look for in google :) I'd like to visualize math patterns on the iPhone, similar to this http://itunes.apple.com/us/app/patterns-lite/id304565312?mt=8 ... If someone could point me into the right direction then that would be fantastic. Original...

Why isnt int pow(int base, int exponent) in the standard C++ libraries?

I feel like I must just be unable to find it. Is there any reason that the c++ pow function does not implement the "power" function for anything except floats and doubles? I know the implementation is trivial, I just feel like I'm doing work that should be in a standard library. A robust power function (ie handles overflow in some consi...

Image Line Trace Math Help Hard To Explain

Hi all, sorry for the confusing title, its really hard for me to explain what i want. So i created this image :) Ok so the two RED dots are points on an image. The distance between them isnt important. What I want to do is, Using the coordinates for the two dots, work out the angle of the space between them (as shown by the black line...

Why is my implementation of the Sieve of Atkin overlooking numbers close to the specified limit?

My implementation of Sieve of Atkin either overlooks primes near the limit or composites near the limit. while some limits work and others don't. I'm am completely confused as to what is wrong. def AtkinSieve (limit): results = [2,3,5] sieve = [False]*limit factor = int(math.sqrt(lim)) for i in range(1,factor): for j in range(1, fac...