# Questions tagged [math]

14478 questions

-2

votes

0

answer

17

Views

### Make a Java Program to Differentiate Equations

I want to make a Java Program to Differentiate Equations.
That way the user inputs the number of Differentiation, first. Then inputs the equation to solve.
Sample input:
1
3x^2-5x^3+5x-7.5x
Sampe ouput:
-15x^2+6x^2-2.50

1

votes

1

answer

174

Views

### Scaling object using delta time?

I'm trying to scale and object with some easing. Which works fine. But I also want to apply a delta time value to the actual scaling. I am just puzzled where to add the value.
Here's the scale easing code:
scale += (MIN_SCALE - scale) * 0.6;
How would I apply the delta time value? It's not lik...

4

votes

0

answer

33

Views

### How to refer to “equivalent” algorithms

This is a bit of a 'soft question', so if this is not the appropriate place to post, please let me know.
Essentially I'm wondering how to talk about algorithms which are 'equivalent' in some sense but 'different' in others.
Here is a toy example. Suppose we are given a list of numbers list of length...

1

votes

1

answer

89

Views

### How to represent Complex plane regions in SymPy?

I have recently started using SymPy, I know there are real intervals in it to represent regions in complex plane, but is there something we can do to represent regions in complex plain?
For example: Represent a disk of radius 2 in upper two quadrants in the complex plane.

1

votes

3

answer

2.4k

Views

### Prime Number Generator in C

This is the Link to the problem: http://www.spoj.com/problems/PRIME1/
Basically we get two limits and we have to print out all the primes between them...
Here is my Code (Language == C) :
#include
void IsPrime(int test){
for(int i= 2; i

1

votes

2

answer

79

Views

### Converting a range of integers exponentially to another range

I'm trying to convert a range of numbers to a another range (in an exponential way). I'm trying to do this in python. I don't have a background in mathematics (nor a formal education in computer science actually), so I'll do my best to explain my question in a clear manner.
Let's say I have the fol...

1

votes

1

answer

32

Views

### cuda “rounding modes” of reciprocal functions [duplicate]

This question already has an answer here:
Semantics of __ddiv_ru
1 answer
Looking at Cuda-Math-Api documentation, functions
__frcp_rd compute 1/x in a round-down mode
__frcp_rn compute 1/x in a round-to-nearest-even mode
__frcp_ru compute 1/x in a round-up mode
__frcp_rz compute 1/x in round-...

0

votes

0

answer

11

Views

### What is the complexity of an algorithm: T (n) = 3 * T (n ÷ b) + n² + 1?

What is the complexity of an algorithm: T (n) = 3 * T (n ÷ b) + n² + 1?
Ask a question
one
Can you help me know what is the complexity of: T (n) = 3 * T (n ÷ b) + n² + 1. When n> 1 ?.
I have been trying to understand a little the master method for the calculation of algorithmic complexities sinc...

0

votes

0

answer

30

Views

### How to calculate jump based on delta time?

I'm trying to make a little game with javascript (no engine) and I want to get rid of frame-based animation.
I successfully added delta time for horizontal movements (work fine with 60 or 144fps).
But I can't make it work with the jump, height (or the strength) isn't always the same, and I don't kno...

0

votes

1

answer

20

Views

### Value domain error when calculating distance using specific longitude and latitude

So I used the distance function found on 'https://gist.github.com/nickjevershed/6480846' as shown below
def dist(lat1, long1, lat2, long2):
# Convert latitude and longitude to
# spherical coordinates in radians.
degrees_to_radians = math.pi/180.0
# phi = 90 - latitude
phi1 = (90.0 - lat1)*degrees_t...

1

votes

2

answer

1.9k

Views

### numpy - Sample repeatedly from matrix using np.random.choice

I have a 2D array, where each row is a direction:
directions = np.array([[ 1, 0],
[-1, 0],
[ 0, 1],
[ 0,-1]])
I want to sample several rows from this, and then do a cumsum (to simulate a random walk). The best approach would be to use np.random.choice. For instance, to sample 10 steps, do this:
np.r...

3

votes

2

answer

29

Views

### Monte Carlo Method not accurate

In celebration of Pi Day, I decided to implement the Monte Carlo method to approximate the value of π, but my algorithm doesn’t seem to be working.
I've tried running with different parameters, but I always get approx 3.66
I've tried debugging but I can't figure it out.
public class ApproximatePi...

0

votes

1

answer

18

Views

### factorial of a negative number exceeds maximum call stack size

Why is the maximum call stack size exceeded when attempting to apply this simple factorial function to a negative number?
function factorial(n) {
if (n == 0) {
return 1
}
return n * factorial(n - 1)
}
I understand that factorial functions are meant for non-negative integers, but I'm wondering...

2

votes

0

answer

9

Views

### Explain the implementation of Euler's Totient Implementation

I have seen this code in a coding platform to efficiently calculate the euler's totient for different values.
I am not being able to understand this implementation. I really want to learn this. Could anyone please help me explain this?
for(int i = 1; i < Maxn; i++) { // phi[1....n] in n * log(n)
phi...

1

votes

1

answer

642

Views

### shadow mapping - transforming a view space position to the shadow map space

I use deferred rendering and I store a fragment position in the camera view space. When I perform a shadow calculation I need to transform a camera view space to the shadow map space. I build a shadow matrix this way:
shadowMatrix = shadowBiasMatrix * lightProjectionMatrix * lightViewMatrix * inver...

1

votes

2

answer

119

Views

### Calculate multiple select dropdown

I have a multiple selection menu like so:
Starter
Bronze
Silver
Gold
Other
I want to do a calculation based on the data-cost and not the value of user selection, so if the user selects both Starter and Bronze, the value in the id of 'ammountToPayField' will be 25, but then if they decide they only w...

1

votes

2

answer

46

Views

### Is it possible to add mathematical symbols in x-axis values?

Instead of adding mathematical symbols in x-labels, I'm trying to add $t_[1,n]$, $t_[2,n]$ and $t_[3,n]$ symbols at 0, 40 and 85 points in x-axis values, respectively. For doing so, my codes are
m=c(rnorm(40,0,.5),rnorm(45,5,.5));
plot(rep(1:85,1), m, type='l', lty=1, xaxt='n', yaxt='n',ann=FALSE,...

1

votes

1

answer

33

Views

### Trying to solve a proportionnality issue here

In my code i generate randoms integer between 0 and 60 and i draw lines based on these.
I just want my lines fit the ordinate vertical line without touching my randoms integer... I guess it's kind of a mathematics problem but i'm really stuck here!
Here's my code first:
Windows.java:
public class W...

1

votes

2

answer

99

Views

### Obtaining the constant that makes the integral equal to zero in Matlab

I'm trying to code a MATLAB program and I have arrived at a point where I need to do the following. I have this equation:
I must find the value of the constant 'Xcp' (greater than zero), that is the value that makes the integral equal to zero.
In order to do so, I have coded a loop in which the the...

1

votes

2

answer

1.8k

Views

### Permutations &/ Combinations using c++

I need a different version of permutations for my code. I could able to achieve what I want but it is not generic enough. my algorithm keeps going bigger along with my requirements. But that should not be.
This is not a home work for any one, I need it for one my critical projects, wondering if any...

1

votes

1

answer

624

Views

### Apply matrix transformation to a sphere

I have a Sphere structure that looks like this
struct Sphere {
vec3 _center;
float _radius;
};
How do I apply a 4x4 transformation matrix to that sphere? The matrix may contain a scale factor, a rotation (which will obviously will not affect the sphere) and a translation.
The current approach I'm us...

1

votes

1

answer

202

Views

### Approximating Subdivision Surfaces with Gregory Patches

In the paper from Charles Loop, et. al, on approximating catmull-clark subdivision with Gregory patches here: http://research.microsoft.com/en-us/um/people/cloop/SGA09.pdf
... the paper shows how to compute edge points like so:
However, I was confused as to how to compute these (in red):
I tried rea...

1

votes

2

answer

96

Views

### Simple Calculation gives wrong result

I have this simple piece of code:
Logger::LogFloat('width', m_BMPLoader->GetWidth());
Logger::LogFloat('height', m_BMPLoader->GetHeight());
Logger::LogFloat('width / 4', (m_BMPLoader->GetWidth() / 4));
Logger::LogFloat('height / 4', (m_BMPLoader->GetHeight() /4));
Logger::LogFloat('-width / 4', -(m_...

1

votes

1

answer

36

Views

### Matlab Evaluation with Symbolic Matrices

syms a b;
T = sym('T',[1 5]);
z = a + b + T(1) + T(2);
a = 3;
I want the answer as 3+b+T1+T2, but eval(z) is not working. What can I do?

1

votes

2

answer

366

Views

### Can I move objects in a JFrame(JPanel) along lines other than y=0, x=0, y=x and y=-x?

I want to make a program that draws a given number of points moving out from the center of the JPanel in a circle/square to infinity. For example 10 points, the first line is at 0 degrees to the y=0 line, the second is 36 degrees, 72, 108...
My problem is that the coordinates of the points are integ...

1

votes

2

answer

818

Views

### Rotating a line around a circle

I have two arcs with strokes and i want to have a line animate between them. The line should animate perpendicular to the points of the inner circle.
Here's something that I hacked together that is almost what I want.
things that are wrong with it are:
the length of the line is not the length betwee...

1

votes

3

answer

337

Views

### create a bezier curve from arc in javascript

I want to create a quadratic bezier curve from the two end points on a arc (x1, y1, x2, y2) and either the center point (cx,cy) or radius.
At one point, I thought that I could set the two control points to the intersection of the tangents, but that does not seem to work.
While an exact answer wou...

1

votes

1

answer

307

Views

### Algorithm - GCD and LCM problems

Input for this problem is an array A of positive integers and single positive integer k. The output of the program is True if k is in the set S defined below, False otherwise.
Define the set S as follows:
if x is in A then x is in S
if x and y are in S, then GCD(x,y) is in S
if x and y are in S,...

1

votes

1

answer

107

Views

### Mimik leveling algorithm

I'm trying to mimik the leveling algorithm for Steam's leveling system.
Here are the level details:
http://steamcommunity.com/sharedfiles/filedetails/?id=457523080
When you get started, each badge you craft will increase your level. Most badges give 100 XP, and it takes 100 XP to get to the next lev...

1

votes

3

answer

66

Views

### Algorithm for finding similar formulas [closed]

I am looking for some algorithms to find similar formulas in a quantitative way.
For example, given three formulas below:
1. test = a + 4 - b
2. test = a - 16 + 2 * b
3. test = a + 5
I can somehow calculate the similarity between them, say:
Similarity(1,2) = 0.5
Similairty(2,3) = 0.1
Is there any s...

1

votes

1

answer

43

Views

### How to group identical collections together

I am randomly sampling a number of matrices A and each one computing the probability mass function (pmf) for Ax. x is random with elements from +-1 and A is a matrix with elements from +-1. My code so far looks like:
from collections import Counter
import numpy as np
import itertools
def pmf(L):
C...

1

votes

2

answer

400

Views

### Math operations precision in PHP 5, PHP 7

When developing calculator in PHP 5+, can programmer get results without thinking on errors of rounding and imprecise representation of decimal numbers?
I mean built-in perfect ways to get, for example, results with given accuracy.
Or each operation like $x = $y * $z + 0.77 must require to develop a...

1

votes

1

answer

49

Views

### javascript simple math issue

I have a simple math problem in javascript that I can't solve.
var prodajna_avg = parseFloat(vpc - (vpc * (rab_avg / 100))).toFixed(2);
var nabavna = parseFloat();
document.getElementById('brutto_avg').textContent = parseFloat(prodajna_avg - nabavna);
Problem is in line three. I don't get the correc...

1

votes

1

answer

326

Views

### Evaluation of math formula in Python (with custom variable names and subscripts)

I need to evaluate a bunch of math formulas (string format) for a time series for example:
' y = 0.5 * gdp[t] + 0.2 * ln( sp500[t-2] ) '
The math formula has two elements I need to take care of:
Custom variable names (e.g. gdp) that refer to a time series / array
Variable subscripts to denote indice...

1

votes

2

answer

77

Views

### Understand math done for endpoint in canvas arc

Given that i want to draw a circle in canvas that looks like below:
Now i am using the circliful plugin ,
Now the math done behind the scenes is like so:
if (type == 'angle') {
startAngle = 2.25 * Math.PI;
endAngle = 2.4;
circ = 1.53 + Math.PI;
quart = 0.73 + Math.PI / 0.996;
}
The above math gets...

1

votes

1

answer

256

Views

### Time complexity of doubly recursive function

So this is the code:
int test ( int n)
{
if (n ≤2) return 1;
else return test(n-2) * test(n-2);
}
I'm not confident in how to reason about this recursive function. I tried mapping the N value to the recursion depth like so:
N = 2 -> 0 recursions
N = 4 -> 2
N = 8 -> 14
But to be honest I'm not...

1

votes

1

answer

131

Views

### Calculate time t along a 2D cubic bezier equal to a given tangent vector

I have a cubic bezier defined by four points. I need to find the time t along the cubic bezier where the tangent is equal to a given vector. This problem is not as straightforward as it may seem on first glance. I'll explain the basic math first for how I approached it so you can find flaws and poss...

1

votes

2

answer

142

Views

### Turning XY data into polygon, and then sorting them clockwise

I got data set (formed by sum of sub-sets, hence its unsorted) and Id like to turn it into polygon.
Is there a simple Matlab procedure that sorts/turns data set into polygon? The data form outline of a polygon, BUT they are NOT in correct order:
(to the left). The polygon must consist of ALL the poi...

1

votes

2

answer

190

Views

1

votes

2

answer

322

Views

### How to print output of .bas file to text

I am trying to print coordinate outputs of a program to a text file in order to use it in another program but I don't really know anything about GWBASIC and its my first time using MS-DOS. I need it to open a text file named plot.txt and print output there and save it without actually plotting on GW...