math

C/math model of a transistor.

I'm look at writing some code to simulate some electronics and need to model some transistors. Does anyone know of a resource that has models for several kinds? (Or at least several kinds with high gate impedances and fairly linear analog performance as that's what I'm going to need.) Systems of equations and tables of values for stock ...

Theoretical Algorithm for finding closet 2 points on a circle in O(n)

Given n points on the outline of the unit circle, I want to calculate the closest 2 points. The points are not ordered, and I need to do it in O(n) (so I cannot sort them clockwise...) I once knew the solution for this, but forgot it... the solution includes hashing, and splitting the circle to n or more slices. If you found an algori...

List all k-tuples with entries summing to n, ignoring rotations

Is there an efficient algorithm for finding all sequences of k non-negative integers that sum to n, while avoiding rotations (completely, if possible)? The order matters, but rotations are redundant for the problem I'm working on. For example, with k = 3 and n = 3, I would want to get a list like the following: (3, 0, 0), (2, 1, 0), (2...

Help with Change back ($1, $5, $10, $20, Q, D, N, & Pennies)

Hey everyone, could anyone help me out with doing the Dollars in this function. It does the change just fine but it does all of the amount back in change and i want to big bills ($1,$5,$10, & $20)'s in dollars and the change in Q/D/N/P's. Dim Quarters As Integer Dim Dimes As Integer Dim Nickels As Integer Dim Pennies As Integer Sub Get...

Confused on Miller-Rabin

As an exercise for myself, I'm implementing the Miller-Rabin test. (Working through SICP). I understand Fermat's little theorem and was able to successfully implement that. The part that I'm getting tripped up on in the Miller-Rabin test is this "1 mod n" business. Isn't 1 mod n (n being some random integer) always 1? So I'm confused at ...

Calculate Age of Debt in SQL Server

I have three tables: Charges Payments Adjustments Each has a value, called Amount. There are no allocations done on this data, we are assuming the oldest Payments are paying the oldest Charges or Adjustments. Each Amount could be +ve or -ve. I need to produce a report which shows the age of the debt, based on the current balance bein...

How can I reproduce a scribbly pattern like this in code?

I made this graph in wolfram alpha by accident: Can you write code to produce a larger version of this pattern? Can you make similar looking patterns? Readable code in any language is good, but something that can be run in a browser would be best (i.e. JavaScript / Canvas). If you write code in other languages, please include a scr...

How do I utilize string "*" or "\" as mathematical operators?

I want to use "*" or "\" as mathematical operators as such: "I am going to clarify" dim tbox as textbox tbox.text = "*" dim i as integer = 8 tbox.text 3 "End Clarify" dim [mult] as string = "*" dim [div] as string = "\" dim i as integer = 8 [mult] 3 and the result would be i is equal to 24 or dim i as integer = 8 [div] 2 ...

Is there a C/C++ function to safely handle division by zero?

We have a situation we want to do a sort of weighted average of two values w1 & w2, based on how far two other values v1 & v2 are away from zero... for example: If v1 is zero, it doesn't get weighted at all so we return w2 If v2 is zero, it doesn't get weighted at all so we return w1 If both values are equally far from zero, we do a me...

Need help with an assignment from the MIT opencourse. Calculating prime numbers.

So, I have a very shotty background in programing and I have, for a very long time, attempted to learn through various lessons, though, no matter how good the lesson or tutorial is said to be, it always loses me at some point. For example the CarlH lectures lost me at around unit 5 part 1 and 2 where it jumped the shark and neglected to ...

Extremely Large Integers in PHP

Possible Duplicate: Working with large numbers in PHP. I run a completely useless Facebook app. I'm having a problem with PHP's support for integers. Basically, users give themselves ridiculous numbers of points. The current "king" has 102,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,002,557,529,927 poin...

How do I convert a number to a custom 2char BaseX and back? (aka: How to do Azure Table Math)

Similar in how one would count from 0 to F in Hex, I have an array of numbers and letters I want to "count" from... and when I hit the max value, I want to start all over again in the "tens" column. I need this to increase storage efficiency in Azure Table, and to keep my PrimaryKeys tiny (so I can use them in a tinyURL). First conside...

Processing - Line Implementation Help

I jumped into Processing (the language) today. I've been trying to implement a line without the line() function. In other words, I'm trying to replicate the line() function with my own code. I'm almost there, but not. (There's a screen, and you can click around, and this function connects those clicks with lines.) There are four differe...

math, coordinates

Hi. now i making some problem with JAVA, but don't remember how get lenght between to coordinate-system. Ex. point A (3,7) Point B (7,59) I want to know how count distance between point a and b. very thanks for your answers. :-) ...

Math.Pi constant is wrong

I'm well aware that a Double has only so many bits of precision, but we should still try to achieve high accuracy if possible. So I certainly do not expect to see this in the official .NET 4 system library. // Summary: // Represents the ratio of the circumference of a circle to its diameter, // specified by the constant, π. publ...

How to get homography matrix in such case? (from one still image)

In my case as input I have such data structures: original image (RGB pixels), objects (squares) with lines crossing points in pixels (x,y) on Image Plane. I have image like this In my particular case the Image Plane has 3 quadrilaterals - projections of real world squares, which, as we know, have same size, lying on the same plane, w...

Representing Math Equations as Java Objects

I am trying to design a way to represent mathematical equations as Java Objects. This is what I've come up with so far: Term -Includes fields such as coefficient (which could be negative), exponent and variable (x, y, z, etc). Some fields may even qualify as their own terms alltogether, introducing recursion. -Objects that extend Term ...

Processing/Line Graphing - Help

I posted something similar yesterday, but got nothing. I spent a few hours today problem-solving, but didn't progress any. I'm using Processing (the language) and trying to implement a method that draws a line between two points. (I don't want to use the library's line() method.) My lineCreate method works great for positive slopes, bu...

cos of degrees not matching the cos of equivalent radians

All math functions in JavaScript use radians in place of degrees. Yet they are either unequal, or I am way off base. The conversion from degrees to a radian is: var rad = angle * Math.PI / 180 A 90 degree angle equals 1.57079633 radian The cosine of a 90 degree angle equals 0. The cosine of a 1.57079633 radian equals -3.20510345 × 1...

Java: Generating a random numbers with a logarithmic distribution

I am attempting to generate a random numbers with a logarithmic distribution. Where n=1 occurs half of the time, n=2 occurs a aurter of the time, n=3 occurs an eight of the time, etc. int maxN = 5; int t = 1 << (maxN); // 2^maxN int n = maxN - ((int) (Math.log((Math.random() * t)) / Math.log(2))); //...