math

Why does this produce a stretched Fractal?

Here is pseudo-code of how I setup an array representing the MandelBrot set, yet it becomes horribly stretched when leaving an aspect ratio of 1:1. xStep = (maxX - minX) / width; yStep = (maxY - minY) / height; for(i = 0; i < width; i++) for(j = 0; j < height; j++) { constantReal = minReal + xStep * i; constantImag = minImag +...

Help on string handling in C

In a program to find whether the given number is an Armstrong number, I stored the input no (3 digit) as string as follows. char input[10]; scanf("%s",&input); Now I have to calculate cube of each digit by using pow method of math.h as follows. int a; a = pow(input[0],3); By coding like this, I could not get correct result. If I p...

How can I simplify a basic arithmetic expression?

How can I simplify a basic arithmetic expression? e.g. module ExprOps where simplify :: Expr -> Expr simplify (Plus(Var"x") (Const 0)) = Var "x" What do I have to do? ...

Statistical Analysis of Server Logs - Correctness of Extrapolation

We had an ISP failure for about 10 minutes one day, which unfortunately occurred during a hosted exam that was being written from multiple locations. Unfortunately, this resulted in the loss of postback data for candidates' current page in progress. I can reconstruct the flow of events from the server log. However, of 317 candidates, ...

Which particular software development tasks have you used math for? And which branch of math did you use?

I'm not looking for a general discussion on if math is important or not for programming. Instead I'm looking for real world scenarios where you have actually used some branch of math to solve some particular problem during your career as a software developer. In particular, I'm looking for concrete examples. ...

Determine Whether Two Date Ranges Overlap

Given two date ranges, what is the simplest or most efficient way to determine whether the two date ranges overlap? As an example, suppose we have ranges denoted by DateTime variables StartDate1 to EndDate1 and StartDate2 to EndDate2. ...

Choosing an attractive linear scale for a graph's Y Axis

I'm writing a bit of code to display a bar (or line) graph in our software. Everything's going fine. The thing that's got me stumped is labeling the Y axis. The caller can tell me how finely they want the Y scale labeled, but I seem to be stuck on exactly what to label them in an "attractive" kind of way. I can't describe "attractive...

Blogs to freshen up my math (in practice)

My question, his question, but blogs as resources to be specific. I find blogs great to keep up to date... refresh material... So do you know any blogs who tackle math-related programming problems... ...

Strange floating-point behaviour in a Java program

In my program I have one array with 25 double values 0.04 When I try to sum these values in a loop I get following results: 0.0 + 0.04 = 0.04 0.04 + 0.04 = 0.08 0.08 + 0.04 = 0.12 0.12 + 0.04 = 0.16 0.16 + 0.04 = 0.2 0.2 + 0.04 = 0.24000000000000002 0.24000000000000002 + 0.04 = 0.28 0.28 + 0.04 = 0.32 0.32 + 0.04 = 0.36 0.36 + 0.04 = 0....

How can you determine a point is between two other points on a line segment?

Let's say you have a two dimensional plane with 2 points (called a and b) on it represented by an x integer and a y integer for each point. How can you determine if another point c is on the line segment defined by a and b? I use python most, but examples in any language would be helpful. ...

Should we compare floating point numbers for equality against a *relative* error?

So far I've seen many posts dealing with equality of floating point numbers. The standard answer to a question like "how should we decide if x and y are equal?" is abs(x - y) < epsilon where epsilon is a fixed, small constant. This is because the "operands" x and y are often the results of some computation where a rounding error is in...

How deterministic is floating point inaccuracy ?

I understand that floating point calculations have accuracy issues and there are plenty of questions explaining why. My question is if I run the same calculation twice, can I always rely on it to produce the same result? What factors might affect this? Time between calculations? Current state of the CPU? Different hardware? Language ...

Other examples of magical calculations

I have seen this topic here about John Carmack's magical way to calculate square root, which refers to this article: http://www.codemaestro.com/reviews/9. This surprised me a lot, I just didn't ever realized that calculating sqrt could be so faster. I was just wondering what other examples of "magic" exist out there that computer games...

c# evaluating string "3*(4+2)" yield int 18

Is there a function the the .Net framework that can evaluate a numering expression contained in a string and return the numeric result? IE: string mystring = "3*(2+4)"; int result = EvaluateExpression(mystring); Console.Writeln(result); prints 18. Is there a standard framework function that you can replace my EvaluateExpression with...

Project Euler #211 - efficiency issue

I've been slowly working my way through the list of Project Euler problems, and I've come to one that I know how to solve, but it seems like I can't (given the way my solution was written). I am using Common Lisp to do this with and my script has been running for over 24 hours (well over their one minute goal). For the sake of concisen...

Prerequisites Needed to Read Books on Neural Networks (and understand them)

I've been trying to learn about Neural Networks for a while now, and I can understand some basic tutorials online, and I've been able to get through portions of Neural Computing - An Introduction but even there, I'm glazing over a lot of the math, and it becomes completely over my head after the first few chapters. Even then its the lea...

Matrix Template Library matrix inversion

I'm trying to inverse a matrix with version Boost boost_1_37_0 and MTL mtl4-alpha-1-r6418. I can't seem to locate the matrix inversion code. I've googled for examples and they seem to reference lu.h that seems to be missing in the above release(s). Any hints? @Matt suggested copying lu.h, but that seems to be from MTL2 rather than MTL4....

Can I calculate the average of these numbers?

Hi folks, I was wondering if it's possible to calculate the average of some numbers if I have this: int currentCount = 12; float currentScore = 6.1123 (this is a range of 1 <-> 10). Now, if I receive another score (let's say 4.5), can I recalculate the average so it would be something like: int currentCount now equals 13 float cur...

How to calculate percentages?

I want to calculate what is $x percentage of a $total. $x could be 15%, 20%, etc, and $total could be 1000, 2000, etc. So I'd want the 15% of 1000, for example. What is the formula for calculating this? (I know this isn't exactly a coding question but I'm coding this feature and need help! ...

3D surface Reconstruction algorithm

I have a 3D surface ( such as a cone). It is projected to a 2D plan in the form of contour, meaning that different Z will have different lines on 2D plan. The problem is from the contour, how to recover the 3D surface by using interpolation? We only know about the z difference between different contor lines. ...