## [Solved] How to solve this mathematical equation in php [closed]

Just group the D’s first and dont hardcode the indices, use \$i \$S = array(); \$D = array(); \$M = array(“1″=>30,”2″=>31,”3″=>30); \$Y = array(“1″=>360,”2″=>360,”3″=>360); \$O = 30000; \$P = 0.3; \$N = 10509.74; for(\$i = 1, \$size = count(\$M); \$i <= \$size; \$i++){ \$final_D = 0; // group the D’s first (O-D1), (O-D1-D2), … and … Read more

## [Solved] Why is my code miscalculating the total force from a list of (magnitude, angle) pairs? [closed]

from math import sqrt, sin, cos, atan2, degrees, radians def find_net_force(forces): h_force = sum( [ force[0] * cos(radians(force[1])) for force in forces ] ) v_force = sum( [ force[0] * sin(radians(force[1])) for force in forces ] ) r_force = round(sqrt((h_force ** 2) + (v_force ** 2)), 1) r_angle = round(degrees(atan2(v_force, h_force)), 1) return (r_force, r_angle) … Read more

## [Solved] How to make every ‘beginner’ shown at random during the run of the program [closed]

So this isn’t exactly an answer for the specific way you decided to go about this program but this is a much simpler way: from random import randrange def beginner_addition(): A = randrange(1,11) # Increase range on harder questions B = randrange(1,11) # Ex. for intermediate_addition(), randrange would be (10,21) maybe… C = A + … Read more

## [Solved] Why does floating-point arithmetic not give exact results when adding decimal fractions?

Binary floating point math is like this. In most programming languages, it is based on the IEEE 754 standard. The crux of the problem is that numbers are represented in this format as a whole number times a power of two; rational numbers (such as 0.1, which is 1/10) whose denominator is not a power … Read more

## [Solved] Convert loop into mathematical equation

for loop can be simplifed to x= (pow(3,n)-1)/2 I have double checked this here:http://www.wolframalpha.com/input/?i=sum+pow%283%2Ci%29+for+i+from+0+to+%28n-1%29 3 solved Convert loop into mathematical equation

## [Solved] Formula for Mapping three values [closed]

With (val>>1)-(val & 1) you get your first result: 0 -> 0 1 -> -1 2 -> 1 The alternative result can be got with (val & 1)-(val>>1): 0 -> 0 1 -> 1 2 -> -1 0 solved Formula for Mapping three values [closed]

## [Solved] Generating all triples from a graph?

As discussed in the comments to the question, it’s not very clear exactly what epitaph‘s setup is, and for some reason s/he seems unwilling to clarify. But let’s suppose that the “graph” is actually simply represented by a distance matrix (which may possibly be what the mess of numbers and Xs in the question is … Read more

## [Solved] Cannot find the value of X in Java 42L + -37L * X == 17206538691L

It’s not completely clear what you are looking for, but note that java long arithmetic is effectively done mod 264. You can investigate modular inverses and the extended euclidean algorithm yourself, as well as how java handles integer overflow. The BigInteger class makes doing these experiments relatively easily, as this example shows. public class Main … Read more

## [Solved] Why is this while loop an infinite loop? High school introduction to CS exam review [closed]

You’re not updating the value of b inside the loop, so its value is always 6. You need to use an assignment operator to actually set a new value. So, use b = b + 3; or b += 3; instead. 1 solved Why is this while loop an infinite loop? High school introduction to … Read more

## [Solved] How to generate Random point(x,y) in Java [closed]

Take a look at article https://www.tutorialspoint.com/java/util/java_util_random.htm. All you need to do is to generate pairs of floats in range (-1,1). You should use method nextFloat() from class Random. It will give you numbers in range (0,1). Then multiply it by 2 and subtract 1 and you will have numbers in desired interval. 0 solved How … Read more

## [Solved] Keep getting math domain error [closed]

As others said, you should call sqrt() only with proper values. So better do … #Check discriminant discrim = float((bval**2)-(4*aval*cval)) if float(discrim >= 0): # now it is ok to calculate the roots… root1 = – bval + math.sqrt(discrim) root2 = – bval – math.sqrt(discrim) if float(discrim > 0): print (“Roots at:”, root1, root2) else: … Read more

## [Solved] How to multiply each element in an array with a different number (javascript) [closed]

Fixed number for all index var array = [0, 1, 2, 3]; array.map( function(n){ return (n* number to be multiplied); } ); Different number for each index var array = [0, 1, 2, 3], numberToBeMultiplied = [1,3,5,7]; array.map( function(n, i){ return n * numberToBeMultiplied[i]; }); You can also push the returning elements in an array. … Read more

## [Solved] Code does not output expected value; how to modify it to obtain the expected result? [closed]

Use braces for complex operations. Also, you should remember BODMAS Rule: Bracket Of Divide Multiply Addition Subtraction int ans=(42+45-48-5-15+20)*2; 0 solved Code does not output expected value; how to modify it to obtain the expected result? [closed]

## [Solved] An equation which gives me 10 = 0 but 100 = 100

Finally I got my answer, the equation is something like this: X = (Y*10-100)/9 Now try putting any value between 10 to 100 in it. solved An equation which gives me 10 = 0 but 100 = 100

## [Solved] Why JavaScript Math.random() returns same number multiple times

Random numbers can appear in streaks; that’s part of being random. But over time the law of large numbers should take over and even out those streaks. You can test that easily enough by running this a bunch of times and counting: var numbers = Array(523,3452); let counts = [0,0] for (let i = 0; … Read more