Category "math"

How do I fill Matrix4 with translation, skew and scale values in flutter?

Suppose, I have these values for a container of height 200 and width 300: scaleX = 0.9198 scaleY = 0.9198 skewX = -0.3923 skewY = 0.3923 translateX = 150 transl

How to put mathematical equations in source code without making it unreadable?

When implementing complex calculations, I found that readability suffered a lot. For example, this formula is absolutely unreadable when translated to code (I c

Scaling the X axis of a rotated ellipse

I have a scatter plot and I'm allowing points to be selected by drawing an ellipse like so: In the above image the X axis and Y axis are scaled differently. I'

Scale current item to 1

I wonder how to scale the current index from 1 to 0.8 when swiping to the next item. I've been building a carousel on how to make the centered item from 1 to 0.

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