I'm studying the cordic. And I found the cordic gain. K=0.607XXX. From CORDIC, K_i = cos(tan^-1(2^i)). As I know the K is approched 0.607xxx.when I is going to infinity this value come up with from all K multiplying. I understand the reason of exist each k. But I am curioused...

So I have a simple form that provides a product cost, markup and final sale price. However, angularjs is not returning the correct value for what I am providing it. Consider the following: I have a product that costs me $50.00 to get in my store. To make a profit,...

I need to solve the exact time complexity for the brute force version of the Traveling Salesman using a recurrence relation. I've worked out the recurrence relation to be as follows: T(n)=T(n-1)*(n-1)+1 But I'm having trouble reducing that that to a closed form of the function, and thus get the...

int main() { double inf = INFINITY; double pi = acos(-1.0); printf("[1]: %f %f\n", atan(inf) / pi, atan(-inf) / pi); printf("[2]: %f %f\n", tan(inf) / pi, tan(-inf) / pi); return 0; } outputs [1]: 0.500000 -0.500000 [2]: -nan -nan Is such behaviour defined by the standard? Is [2] undefined behaviour?...

If I had the following figure shown below and I wanted to scale the top rectangle by some factor such that the left side will still touch the circle like it does now, how would I go about doing that? This is being done in C++ where the rectangles are...

I am trying to create an algorithm that will 'bounce' indefinitely between a number and its negative value, using increments and decrements of 1. For example, using -5 to 5 this function would output the sequence 1, 2, 3, 4, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4,...

Need help with this of python Write a program with 3 functions to find out the (function 1) dot product, (function 2) angle, and (function 3) cross product of two vectors. Program should ask a user to input three points in 3D space such as (x1, y1, z1), (x2, y2,...

When a counter is made up from a fixed number of digits (2 in the title), standard counting-up works by incrementing from the least to the most significant digit and upon overflow reset it. I want to count differently: A 4 digit number in base-10 would be counted up in...

I wrote a script to render a timeline with a dataset in javascript. But i have to mark the area's where no info is found (yellow in the image). I absolutely have no idea how to get the ranges without info in the dataset. (i use momentjs for date calculations)...

The standard Math.sqrt() method seems pretty fast in Java already, but it has the inherent drawback that it is always going to involve 64-bit operations which does nothing but reduce speed when dealing with 32-bit float values. Is it possible to do better with a custom method that uses a...

I want to select a random number from 0,1,2,3...n, however I want to make it that the chance of selecting k|0<k<n will be lower by multiplication of x from selecting k - 1 so x = (k - 1) / k. As bigger the number as smaller the chances to...

I have a program that adds items to a list box. The items consist of a character (+,-,*,/) followed by numbers. I want to get my program to recognize the first character of the item in the list box, and do the math appropriately. However, I cannot seem to get...

When using Java ternary operator or Math functions, is the returned value always up to date, or does the statement have to be reevaluated whenever I need an updated value? Considering: a = myBoolean? 1: 2; a = Math.min(x, y); Does the values of "a" would change dynamically like it...

I have been trying to solve this problem. http://www.spoj.com/problems/DIV/ for calcuating interger factors, I tried two ways first: normal sqrt(i) iteration. int divCount = 2; for (int j = 2; j * j <= i ; ++j) { if( i % j == 0) { if( i / j ==...

I'm trying to figure out the math to find a random point inside a cube. I have something small but it can't take into account the rotation of the cube. Here are some images of my results. Here you can see the cube is rotated to some degree but when...

C++, I want calculate the angle of the direction of the two points. Here is a picture which shows the two points and the direction of how to get the angle of the direction? p1 - start point. p2 - direction point. me need direction angle(facing?) from p1 to p2...

While i was searching for Exponentiation by squaring i got the recursive method there but then i stumbled upon this pseudo code , Which i'm unable to understand fully. function powermod(base, exponent, modulus) { if (base < 1 || exponent < 0 || modulus < 1) return -1 result =...

If i had an array of point structs defined as struct Point{ float x; float y; }; How would I rotate the points in this array by a given angle? As an example: Any help would be appreciated!...

I'm trying to make my robot follow a path that is a drawn SVG path on a webpage. To keep it simple, assume that the SVG Is like so: <svg xmlns="http://www.w3.org/2000/svg"> <path id="path" d="M 100 100 L 300 300 L 100 500 z"> </svg> Which makes a triangle. The robot...

var current = 12000; var june = 14600; var may = 11200; I want percent change with respect to 'current' month parameter. The output should be in percent and it can add or subtract w.r.t. the current month. How to do this?...

This question already has an answer here: Javascript converting second to minutes [duplicate] 2 answers I am developing a web-based application to capture total time of playlist of video. my main problem is that I don't know how can I calculate the total time from an array e.g: 30:00...

Perfect power is a positive integer that can be expressed as an integer power of another positive integer. The task is to check whether a given integer is a perfect power. Here is my code: def isPP2(x): c=[] for z in range(2,int(x/2)+1): if (x**(1./float(z)))*10%10==0: c.append(int(x**(1./float(z)))), c.append(z) if len(c)>=2: return c[0:2]...

This question already has an answer here: Why Are Floating Point Numbers Inaccurate? 3 answers While programming I noticed a difference between the result of math.exp(2) and math.e**2. As you can see below, this difference does not arise when calculating e^1. Not being an experienced programmer, I wondered why...

I think my current problem is related to intercept theorems that everybody learned at school, but that was quite some time ago and I am kind of getting stuck halfway. My Problem: I have two Vectors in a 2 dimensional space called v1 and v2. What I want to know...

I have to solve problem using c++, and can't really come up with solution. The condition is. In a skyscraper there are a lot of offices, on every office door there must be put plate with its number from 1 to the number of the last office. The plate can...

I haven't been able to make this work. I'm trying to make a template for an xsl tranformation of degrees geocoordinates to meters. The function in PHP is like this and works just fine: function degtometers($lon, $lat) { $half_circumference = 20037508.34; $x = round($lon * $half_circumference / 180); $y =...

I found a very interesting thread in the GameDev side, link below: http://gamedev.stackexchange.com/a/43704 I would like to implement this formula to draw a eight/infinity sign into in view, I don't see how I can do this. Someone can give a clue to start the code? Thanks for reading,...

The problem is in Polygon::FindAxisLeastPenetration: double Polygon::FindAxisLeastPenetration(unsigned int *faceIndex, const Polygon &polygonA, const Polygon &polygonB) const { double bestDistance = -std::numeric_limits<double>::infinity(); unsigned int bestIndex; for (unsigned int i = 0; i < polygonA.points.size(); i++) { Vector2D n = polygonA.normals[i]; Vector2D nw = polygonA.rotationMatrix * n; //ROTATION Matrix22 buT = polygonB.rotationMatrix.Transposed();...

I am not sure if power by squaring takes care of negative exponent. I implemented the following code which works for only positive numbers. #include <stdio.h> int powe(int x, int exp) { if (x == 0) return 1; if (x == 1) return x; if (x&1) return powe(x*x, exp/2); else...

I am looking for a basic algorithm that gives more weigh to the recent reviews. So, the output value of the algorithm is mutable. For example, two reviews with exactly the same score, will have a different ranking based on the timestamp of the creation. Review_1 Score 10 creation 10/5/2014...

I'm successfully using Welford's method to compute running variance and standard deviation as described many times on Stack Overflow and John D Cook's excellent blog post. However in the stream of samples, sometimes I encounter a "rollback", or "remove sample" order, meaning that a previous sample is no longer valid...

I have been trying to implement the Chinese Remainder Theorem, for the specific case of just two equations, using the Data.Modular package. The idea is that I can specify each equation with only one modular number (x = a (mod m) using the number a (mod m)). Here is my...

I'm having trouble centering a div post rotation. Here's my fiddle: https://jsfiddle.net/cfy2ztdz/ Move between slides with keyboard 1 & 2 You can see that it finds the middle perfectly without rotation, but post rotation, moving back to 1, moves off page - instead of back to the middle. Where's my...

I'm generating a somewhat unique code that I don't want to repeat within at least 1000 consecutive numbers this is my function. take a number multiply it by another number then take the last $length=5 digits before the decimal point function createPseudoUniqueString($input,$length) { return substr( intval($input*738510.93067),-$length) ; } is there...

I have data in table I want Last Month Consumption and Last Three Month Consumptions for example basis on Reading I have tried this: SELECT tbl.CustomerID ,tbl.CustomerName ,tbl2.Last3Months ,tbl.LastMonth FROM ( SELECT events.event_item_id CustomerID ,items.item_name CustomerName ,MAX(events.event_additional_info) maxR ,MIN(events.event_additional_info) minR ,(MAX(events.event_additional_info) - MIN(events.event_additional_info)) AS LastMonth FROM events INNER JOIN items...

I have a line which has points (x1,y1) and (x2,y2). I wanted to attach a Button to it, it should align with the line by rotating based on the line segment points. I need some help in calculating the rotation angle for the Button.

In my world I have a character wich is always rotated towards the mouse. It is very logical that when the player moves forward or backward, that the character's x coordinate equals it's x coordinate minus (or plus) the cosine of its x coordinate. And the same for its y...

Why does this function give the wrong answer -1 rather than the right answer 1 when I try this? myPow(-1.00000, -2147483648) double QuickPower(double x, int n) { if(n==0){ return 1; } if(n==1){ return x; } if(n>=2){ int res=n%2; double half=QuickPower(x,n/2); return res? Half*half*x: half*half; } } double myPow(double x, int...

int phi (int n) { int result = n; for (int i=2; i*i<=n; ++i) if (n % i == 0) { while (n % i == 0) n /= i; result -= result / i; } if (n > 1) result -= result / n; return result; } I saw...

Lets see if someone can wrap their head around this: if you get the length of a String using length(), the String always being multiples of 3,(in my case: "1.02.03.04.05.06.07.0 etc.") each 3 characters representing a letter, with .1 indicating a capitol letter, how do you use the length to...

NOTE: This is for a homework assignment, but the portion I have a question on is ok to ask help for. I have to script out a sequence 11110000111000110010 (i am using python) without using switches or if statements and only a maximum of 5 for and whiles. I already...

Assume W is a known vector, here I want to find the unique solution a, such that: Sum(min(1,W(i)/a))=M (M is known) Is there any specific name for such kind of function? It would be great if you guys can give me a link for some instructions. Thanks....

i have a normal Java code, that just calculate a x-coordinate, but it is just 0; private static final int startX = (Level.WIDTH / 2) - (Block.LENGTH * (Level.COLUMNS / 2)); At the time of calculating: Level.WIDTH = 1000; Block.LENGTH = 41; Level.COLUMNS = 12; Accord my calculation it must...

Is it possible to perform math operations within HTML, like <div width="50/2">? Or can this only be done using Javascript or CSS?

usually for lottery combinations the formula is "n! / (k!*(n-k)!)", e.g., for a 6/49 game it is "49!/(6!*(49-6)!)" is there a formula to calculate the same with m FIXED values (e.g., the numbers 1, 2, 3, and 4 are fixed) - 2 numbers are free for choice i thought the...

I'm trying to reverse the following code in order to provide a function which takes the buffer and decrypts it. void crypt_buffer(unsigned char *buffer, size_t size, char *key) { size_t i; int j; j = 0; for(i = 0; i < size; i++) { if(j >= KEY_SIZE) j = 0;...

I'm working on a project where I have a pane that goes from 0 to 500 on the x and z, but I need to convert that coordinate (from 0 to 500) to a float in the range of 0.0 to 1.0 in because it is required from some of...

I am trying to prove an equation given in the CLRS exercise book. The equation is: Sigma k=0 to k=infinity (k-1)/2^k = 0 I solved the LHS but my answer is 1 whereas the RHS should be 0 Following is my solution: Let's say S = k/2^k = 1/2 +...

I have an object containing decimals values : evo, meteo and usage I try to display this values with three conditions : values can be positive and negative values must be displayed as percentage without any decimals (A) must be true (A): Math.round(meteo*100)+Math.round(usage*100) = Math.round(evo*100) For example, if we apply...

I want to store mean_2....mean_8, std_2....std_8, and coVariance as separate columns in a file. Help Please? This Code calculates IntervalFeatures of Erp signal with 256 time frames and plots them Datapoints are store in A ___________HowTheCodeWorks________________________________________________ each 1x4 sliding sub-matrix is made a column for eg:- if A is...

I am trying to create a graph using parabola equation (y=x*x). But I am bit confused to calculate the value for control point. How should I calculate the control point value. My JavaScript function: function drawParabola() { ctx.beginPath(); for(i=-2;i<=2;i++) { //formual y= x * x; y = i * i;...

This question already has an answer here: How do you round UP a number in Python? 9 answers Python round up integer to next hundred 6 answers so i'm making a pizza program in Python 3.3 that takes input from the user and prints the amount of pizza's needed....

I've written a short Python script to find the original and minified sizes of a script, by comparing file sizes, and to find the difference and compression ratio. The script itself follows: #! /usr/bin/python import os import sys file1 = sys.argv[1] file2 = sys.argv[2] file1Size = os.stat(file1).st_size file2Size = os.stat(file2).st_size...

How can we use cordic to tanh(x+1)/tanh(x) I can't get a idea about how to apply cordic to above function. In other word, which point on the above function, can we apply cordic?...

This question already has an answer here: Is floating point math broken? 18 answers System.out.println("3.14 - 5 = " + (3.14 - 5)); This statement shows 3.14 - 5 = -1.8599999999999999 in console when the answer is -1.86. How would I be able to fix this error and what...

I am trying to do a homework in math which is find a subset of collection {1,2,..,n} where n is a number given in the code, I cannot get it done with the sublist so I need to get your help with a math programming. For example for n =...

Other than doing this: from itertools import combinations def brute_force(x): for l in range (1,len(x)+1): for f in list(combinations(range(0,len(x)),l)): yield f x = range(1,18) len(list(brute_force(x))) [out]: 131071 How could I mathematically calculate the number of all possible combinations? Is there a way to do it computationally without enumerating the possible...

So I've been working at this on and off for a week, googling and all and I haven't found how to do this. I have a table of "rays" and a table of "lines", and I want the lines to act as mirrors and reflect a ray whenever the ray...

This is the pseudo code for calculating integer factorisation took from CLRS. But what is the point in calculating GCD involved in Line 8 and the need for doubling k when i == k in Line 13.? Help please....

I have a problem where I am trying to prevent repeats of a string. So far the best solution is to compare the strings for a percentage and check if it is above a certain fixed point. I've looked up Levenshtein distance but so far I believe it does not...

I'm having a time series and need to aproximate it with some function which is easy to calculate. It looks like the row is something like (a*x*x + b*x + c) / (d*x + e) Is there a way to find the coeficients automatically (with Matlab or whatever) the so...

I am newbie to XSLT. My am is to remove elements from XML based on a field if it is higher than some threshold value which I will be getting as parameter to it. My XML is as shown below: <tns:PM objectClass="MyNode" objectName="" className="com.project.converter.PMFamilyConverter" interfaceName="ComponentPM" xmlns:tns="http://www.myproject/SS/PMSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.myProject.com/SS/PM.xsd"> <tns:family desc="family0"...

I am trying to write an algorithm for a program to draw an even, vertical gradient across an image. I.e. I want change the pixel color from 0 to 255 along the m rows of an image, but cannot find a good generic algorithm to do so. I've tried to...

What I'm looking to do is find a way that I can have my code return all the combinations of values from a list that add to a variable, returning each answer as a list. For instance, target_number = 8 usingnumbers = [1, 2, 4, 8] returns: [8] [4, 4]...

I'm writing a python script to find out some things about randomization. I have the following code: from random import randint one = 0 two = 0 olddiff = 0 diff = 0 sumdiff = 0 avgdiff = 0 headcounter = 0 counter = 0 while (headcounter < 500000): while...

This is my one dimensional array A, containing 10 numbers: A = [-8.92100000000000 10.6100000000000 1.33300000000000 ... -2.57400000000000 -4.52700000000000 9.63300000000000 ... 4.26200000000000 16.9580000000000 8.16900000000000 4.75100000000000]; I want the loop to go through like this; (calculating mean interval wise) - Interval length of 2,4,8 (a(1)+a(2))/2 - value stored in one block of...

I am doing this small task which I have to arrange asymptotic runtime in ascending order. Here are the runtimes: Here is the order I believe they should go in: log10(n^4), n^3, 2^((log4n)), 2^(100n), e^pi^4096, n! + 12^1000 Is this correct? Or are there any errors? Thanks!...

I did a code like this: public static double myPow(double x, int n){ if(n==0) return 1; double t = myPow(x, n/2); if(n % 2 != 0){ if(n < 0){ return (1 / t * t * x); } else { return t * t * x; } } else {...

I haven't been able to find any information online that doesn't already assume I know things. I wonder if anyone knows any good resources that I can look into to help me wrap my head around what this function does exactly? From what I gather, and I'm pretty certain this...

I'm working on some coderbyte code, and noticed that when I try to get the max item in an array of equal values undefined is returned. When logging the min value is logs 80 and not undefined. Why is this? Updated Code: function noRepeat(arr) { tmp = [] if (arr.length...

Given the exact no. of elements that must be present in the array (let=r) and the max value of the last element of the array (let=n) find the total number of distinct non decreasing arrays possible (all elements of array must be >=0) Example- If r=3 and n=2 then some...

I am trying to Math.floor a scientific notation, but at one point the number gets too big and my current method doesn't work anymore. This is what I am using atm var nr = (number+"").length - 4; if( nr > 1 ) { nr = Math.pow( 10, nr ); number=...

I am building a game, I want to pick a random number between 0 to n, I want to make that picking a higher number will have lower chances. So I asked this question, and based on amit answer, I wrote this: public class Test { private static Random random...

Im trying to generate random integers with logarithmic distribution. I use the following formula: idx = Math.floor(Math.log((Math.random() * Math.pow(2.0, max)) + 1.0) / Math.log(2.0)); This works well and produces sequence like this for 1000 iterations (each number represents how many times that index was generated): [525, 261, 119, 45, 29,...

I've read a dozen articles online about the correct order of rotation, translation and scale matrix multiplication in OpenGL. However, now that I started implementing it myself, I came to the point where I'm really confused. Let's assume that in my code I'm calculating the transformation matrix, and I'm passing...

In my javascript code I have the following Math.log(20) = 2.995732273553991 In my excel formula I try to replicate this with =LOG(20) = 1.301029996 Anyone have any idea why I'm getting two different outcomes? I'd like my excel to match my js. ...

I'm trying to make a Java project that pinpoints the place on a image of a map, when given coordinates (taken from Google Maps). I've tried using the top-left corner of the image (place that has highest latitude, and the lowest longitude), as an some kind of an reference point,...

I am trying to math between value of 0 but in php code it's work properly but when that value come from database then it does not work. Here is a demo to test only PHP code: <?php $a = 0; echo $a+1; ?> The result of this code 1...

I am using this JavaScript/ActionScript code to figure out the angle given two x and y values but it is incorrect: var deltaX = 10; var deltaY = -10; var angleInDegrees:int = -(Math.atan2(deltaY, deltaX) * 180 / Math.PI); trace(angleInDegrees); // 45' The results at a different points: clock x y...

I have been signed up for a while and don't usually post unless I really cannot find an answer, and now, I feel quite stuck. I have only recently started getting familiarized with java Lambda expressions (mainly the function ones) such as BinaryOperator and Bifunction..) I was looking at the...

I got some values from database dynamically, 34 ,104, 1117 I want for 34 to 40, 104 to 110, and 1120, Please Help!

The follow plot shows my question: I would like to add a line between the points of 1e-1 and 1e-2. So I thought just (1e-1+1e-2)/2. But for a log scale that is not "midway". How can I calculate the "visual" midway value between these, or any two points in this...

I am trying to analyze the complexity of the function call to PEL(A[1..n]) where n is a certain power of 3 and PEL is defined by the following algorithm: function PEL(A[m..n]){ if(n - m <= 1) return 1; else { p := [(n - m + 1)/3]; MAKE(A[m..n]); PEL(A[m..n +...

From CORDIC, K_i = cos(tan^-1(2^i)). As I know the K is approached 0.607xxx. How do I approach to 0.607xxx? Also does it mean that I can use 0.607xxx instead of cos(tan^-1(2^I))? I am citing from this article. I am trying to implement hyperbolic tanh function. And so far I understand...

i was playing around in code academy and for some reason when i change the last slaying i the else statement to true instead of making the person invincible it just crashes my browser any ideas why thank you in advance var slaying = true; var youHit = Math.floor(Math.random()*2); var...

I am new to Linux, and I just want a Bash Script to do basic arithmetic operation to a text file 1 2 3 4 and the results should be addition and multiplication in separate text files say add + 5 for 1st text file and mult * 5 in...

Is there a way to calculate pi in Javascript? I know there you can use Math.PI to find pie like this: var pie = Math.PI; alert(pie); // output "3.141592653589793" but this is not accurate. What I want is to be able to calculate it, to have as many digits as...

For some reason, my last prime(int prime) isn't showing up at the end. Any clue ? fyi: primeEval stands for a flag, if the loop ends && primeEval==2, the number is actually a prime number. qty stands for quantity of primes counted. int main(){ long primeEval=0,prime=0,qtyprime=0; time_t timerr=(time(NULL)+10); for (int...

How to create a c code that receive int parameter n and return the value of this mathematical equation f(n) = 3 * f(n - 1) + 4, where f(0) = 1 each time the program receive n , the program should start from the 0 to n which...

If we are told that we can't use modulus operator then how can we take out the last digit of a number. e.g. N=2345, we should get 5. Try to provide a generic solution. What I found: N- N/ 10 * 10 ...

I use Chart.js (http://www.chartjs.org) to show traffic usage for different units using Bar Chart. If I have big range of usage (1 unit 2.5GB, 2 unit 2.5MB, 3 unit 2.5kB, 4 unit 0B) smallest values are not available (I cannot hover over or click on them) when bring them to...

I have been trying to solve below matlab programming question. I have tried my code, but it could not work for some cases. Am I missing something? Question: Write a function called integerize that takes as its input a matrix A of non-negative integers of type double, and returns the...

I have a program at the moment that adds items to a list box, the items consist of a character (+,-,*,/) followed by numbers. I have been attempting to get my program to recognize the first character of the item in the list box and doing the math appropriately all...

I've wrote an implementation of Murmur3 hash and have defined the 128-bit keys as hash128_t typedef struct { uint64_t p1; uint64_t p2; } hash128_t; I'm trying to write my own hashmap using these keys, but I'm not exactly sure how to do arithmetic with a struct nor a number this...

I'm wrangling some bad data in a raster image using GDAL with gdal_calc.py. I'm trying to clip value A at -100 like this: max(A, -100) However, only basic operators (+-/*) and logical operators (><, these return 0 or 1) are allowed. Is there a way to implement this? Got as...

I am new to permutations and combinations. I am provided with the number n and I can make a number with the help of n+1 digits which are 0,1,...n. I need to find in how many ways I can make the sum n by putting these n+1 digits in n...

I need to multiply X with a floating point number in floating point as i don't have floating point operations in my processor. I understand the method but don't know why that method exists? Suppose we want to multiply 2*4.5 in decimal I do the below: 2 * 4.5 (100.1)...

I'm trying to find all possible solutions to the 3X3 magic square. There should be exactly 8 solutions. My code gets them all but there are a lot of repeats. I'm having a hard time tracking the recursive steps to see why I'm getting all the repeats. // This program...

Instead, this operation returns -1.IND, since sqrt(-1) returns -1.IND. Does the domain error mentioned on the C++ reference that this sqrt returns for negative values not retain the info that this is actually i? Is there some way to perform this operation for all negative numbers, so that it returns...

I would like to solve a nonlinear first order differential equation using Python. For instance, df/dt = f**4 I wrote the following program, but I have an issue with matplotlib, so I don't know if the method I used with scipy is correct. from scipy.integrate import odeint import numpy as...