Category "math"

What's the time complexity of prod() in math in Python

Summary) What's the time complexity of math.prod() How to improve this code to get to the pass Details) Currently working on 'Product of Array Except Self' on L

Translating Screen Coordinates [ x, y ] to Camera Pan and Tilt angles

I have a IP Camera which can PTZ. I am currently streaming live feed into the browser and want to allow user to click a point on the screen and the camera will

Discrepancy in Squaring a number stored in double format

I am trying to square a number x but there seems to be some discrepancy in precision while squaring it using Math.pow() and squaring it using multiplication. pu

How do I calculate square root in Python?

I need to calculate the square root of some numbers, for example √9 = 3 and √2 = 1.4142. How can I do it in Python? The inputs will probably be all

Is there a known algorithm for finding which K elements out of N elements have a sum that is closest to a whole number?

As a small example, say I have N=6 elements { 0.03, 0.25000039, 1.391, 500.1, 0.5000001, 1.75001 } and K=3 then the combination { 0.25000039, 0.5000001, 0.

Modular inverses and unsigned integers

Modular inverses can be computed as follows (from Rosetta Code): #include <stdio.h> int mul_inv(int a, int b) { int b0 = b, t, q; int x0 = 0, x1

How to, given UV on a triangle, find XYZ?

I have a triangle, each point of which is defined by a position (X,Y,Z) and a UV coordinate (U,V): struct Vertex { Vector mPos; Point mUV; inline Ve

Plotting all of a trigonometric function (x^2 + y^2 == 1) with matplotlib and python

As an exercise in learning Matplotlib and improving my math/coding I decided to try and plot a trigonometric function (x squared plus y squared equals one). Tr

Rounding negative numbers to the nearest 1,000 that is closest to zero

I'm looking to round numbers to their nearest 1,000 closest to zero. The following code works for positive numbers import math original_number = 1245 new_number

Determine a bounding rectangle around a diagonal line

A user will define a line on screen which will have, when drawn, a given thickness (or width). I now need to be able to determine the coordinates of a bounding

Does the size of the prime number in Shamir's Secret Sharing affect the security of the sharding?

I've been working on an implementation of Shamir's Secret Sharing, and was wondering if the prime number selected will impact on the security. This is mainly be

Interpreting formulas with ΣΣ (two sigma) in Python

Consider the function f(x,y) that equals two sigma (ΣΣ) where i ranges from 1 to 10 and (first sigma) and j ranges from 1 to 10 (second sigma) of th

Formula to calculate adjusted close price like yahoofinance in python

So, I have been trying to create a manual function in python that calculates the adjusted closing price of stocks using dividends and stock splits data but I co

PHP: How to raise number to (tiny) fractional exponent?

I'm doing a calculation in PHP using bcmath, and need to raise e by a fractional exponent. Unfortunately, bcpow() only accepts integer exponents. The exponent i

algorithm to merge two arrays into an array of all possible combinations

Example given in JavaScript: Suppose we have two arrays [0,0,0] and [1,1,1]. What's the algorithm to produce all possible ways these two arrays can be combine.

Basic example of how to do numerical integration in C++

I think most people know how to do numerical derivation in computer programming, (as limit --> 0; read: "as the limit approaches zero"). //example code for d

How to calculate the range of data type float in c++?

As we can see int has 4 byte in memory, that are 32bits, after applying range formula , we can see range of int -2147483648 to 2147483647. I have calculated the

Formula to make the ends of the arms of a spiral galaxy less dense

I want to make a spiral galaxy in Unity 3D using C# ( i use a derived logarithmic spiral ). I want to set the end of the arms less dense than the middle, but mi

Why is my rock/paper/scissors game getting the same random number for multiple function calls?

I have made a functioning (if possibly extremely verbose) game of rock/paper/scissors. If I run the game by calling the function once over and over the 'compute

Is there any way to get the step-by-step solution in SymPy?

Is there any way to get the step-by-step solution in SymPy? For example: x**2-5 = 4 step 1 x**2-5+5=4+5 step 2 : x**2=9 step 3 :x = 3 or x= -3