math

Python: defining my own operators?

I have a bot in python that allows the users to evaluate mathematical expressions (via a set of safe functions), but I would like to define my own operator. Does python support such a thing? ...

Distribution of a sum S over N diffent operands (b1, b2, .., bn), where b1, b2, ... bn are in a fixed ratio, which is determined by another set of operands (a1,a2, .. an)

If the title is completely misleading/unclear please suggest something relevant and better. Consider a situation where: Candidate A gets a total of Ta votes from N constituencies, with distribution: {a1, a2, a3 .. aN} Candidate B gets a total of Tb votes (Ta and Tb are unrelated, which means Ta < Tb, Ta = Tb & Ta > Tb are all possib...

Math.Pow vs multiply operator (performance)

Anyone knows if multiply operator is faster than using the Math.Pow method? Like: n * n * n vs Math.Pow ( n, 3 ) ...

Is there a Java library with 3D spline functions?

In particular, I need a way to represent a curve/spline that passes through a set of known 3D points, and a way of finding other points on the curve/spline, by subdivision/interpolation. For example, if I have a set of points P0 to PN, I want to find 100 points between P0 and P1 that are on a spline that passes through P0 and P1. I see...

About: Rectangle rotation and fitting

hi, after a hard work, my brain turns out of service.. (it is 11:40 P.M. in Turkey) i am doing a rotation job like that: variables: _cx = horizontal center of rect _cy = vertical center of rect _cos = cos value of current angle _sin = sin value of current angle to rotating any point in this rect : function getx(x, y) { retur...

Calculating the area(s) of a rectangle that aren't being overlapped

I've got two rectangles represented by structures that contain the x1, y1, x2, y2 coordinates. One rectangle can be considered the parent, another the child. I already know how to detect if the child rectangle is within the parent rectangle; what I'm trying to figure out now is the simplest, fastest way to determine the rectangular area...

Efficient python code for printing the product of divisors of a number

I am trying to solve a problem involving printing the product of all divisors of a given number. The number of test cases is a number 1 <= t <= 300000 , and the number itself can range from 1 <= n <= 500000 I wrote the following code, but it always exceeds the time limit of 2 seconds. Are there any ways to speed up the code ? from math...

How to check for NaN in python?

float('nan') results in a thingy simply called nan. But how do I check for it? Should be very easy, but i cannot find it. ...

How to implement Slerp for a Point3?

I am trying to implement a Point3.Slerp method, so was looking for some samples but the ones I found seems like it's a whole brand new class to host all the code. Is there a simple, straightforward way to implement it? Basically the ones I have seen was using Matrix types. Can I implement Slerp without matrices, or would that be a disad...

C++ math functions problem (under Linux)

I'm having problem regarding max and sqrt If I include math.h it coudn't find sqrt. So I view the cmath header file and inside it includes math.h, but when I try to open math.h it says that file is not found. SO ithink my math.h is missing in Linux. ...

Simple JavaScript addition issues..

Hi all, I'm not so good with JS and for some reason when I try to add two fields together it joins them rather than adding the sum together.. this is the code I'm trying to use.. function calculateTotal() { var postageVal = document.getElementById('postage').value; //$68.50 var subtotalVal = document.getElementById(...

Calculating larger values of the ackermann function.

I have some code: int CalculateAckermann(int x, int y) { if(!x) { return y++; } if(!y) { return CalculateAckermann(x--,1); } else { return CalculateAckermann(x--, CalculateAckermann(x, y--)); } } Designed to calculate the ackermann function. Above a fairly low number of x and y the ap...

C++ 2D Integration Libraries

Can anyone point out a good C++ library that can do 2D numerical integration. It needs to be able to accept a 2D array of known values, and the spacing between the points can be assumed to be constant (for a start). It is preferable that it have a license which allows modifying the code as needed. ...

Is there an efficient implementation of tetration?

After recently answering a question involving the Ackerman function part of which involved a function for computing the tetration of a number. Which led me to ponder if there was a more efficient way to do it. I did some testing on my own but I'm limited mainly by the fact that even a number such as 5^^3=5^3125 given 5^3 is roughly 10^2...

Image Remapping Algorithm

Hi all, I have been developing (for the last 3 hours) a small project I'm doing in C# to help me choose a home. Specifically, I am putting crime statistics in an overlay on Google maps, to find a nice neighborhood. Here is an example: http://otac0n.com/Demos/prospects.html Now, I manually found the Lat and Lng to match the corners of...

Huge Integer JavaScript Library

Is there any JavaScript library that can be used for calculations involving 700+ Digits? Also, how about the same thing in C++? ...

Scientific math with functional languages?

Are there any serious scientific math libraries made with functional programming languages? From the very nature of functional languages one would think that they are particularly suitable for math, but yet the well-known algorithms seem to be procedural. For instance, the classic Numerical Recipes series is written pretty much in proce...

Trajectory -math, c#

Hi, I am trying to map a trajectory path between two point. All I know is the two points in question and the distance between them. What I would like to be able to calculate is the velocity and angle necessary to hit the end point. I would also like to be able to factor in some gravity and wind so that the path/trajectory is a little...

Plotting a point on the edge of a sphere

So coming from a flash background I have an OK understanding of some simple 2D trig. In 2d with I circle, I know the math to place an item on the edge given an angle and a radius using. x = cos(a) * r; y = sin(a) * r; Now if i have a point in 3d space, i know the radius of my sphere, i know the angle i want to position it around the ...

Is this "Valid mathematical expression" problem P, or NP?

This question is purely out of curiosity. I am off school for the summer, and was going to implement an algorithm to solve this just for fun. That led to the above question, how hard is this problem? The problem: you are given a list of positive integers, a set of mathematical operators and the equal sign(=). can you create a valid math...