Category "math"

Minimum moves to transform a list so that each element equals its own frequency

Given a sorted array like [1,2,4,4,4]. Each element in the array should occur exactly same number of times as element. For Example 1 should occur 1 time, 2 shou

Python Cartesian plane plot and line

I want to create a cartesian plane in python that looks similar to the attached image, where I have 2 sets of coordinates e.g. (7,7) (17.4,20), and a line going

How can I calculate the tens place value of 2^100 in C++?

How can I calculate the tens place value of 2^100 in C++? I tried this; #include <cmath> #include <iostream> using namespace std; int main(){

Convert Calendar Days to Working Days (and Vice Versa) | 4 Day Work Week

I have values corresponding to 'Calendar Days.' I'd like to convert this to 'Working Days.' In this example, a 'Working Day' is defined by Monday through Thurs

Calculate spin frequency from rotation change in degrees

I have an object that rotates in the same direction at a variable speed. I have the ability to measure the angle of this object in degrees (0-360) every frame (

center of mass in each cell of N-dimensional rectilinear grid

I have an n-Dimensional rectilinear grid, such that the edges in each dimension i are given by x_i = {x[i, 0], x[i,1], ..., x[i, Ni-1], x[i, Ni]}, with N_i edge

Plot Cassini ovals in Python using numpy and matplotlib

I am trying to plot Cassini ovals in Python using these parametric equations for x,y. https://mathcurve.com/courbes2d.gb/cassini/cassini.shtml Here is my progra

PCA on sklearn - how to interpret pca.components_

I ran PCA on a data frame with 10 features using this simple code: pca = PCA() fit = pca.fit(dfPca) The result of pca.explained_variance_ratio_ shows: array

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