Questions tagged [math]

Mathematics consists of various operations performed on numerical values in computer science applications. If you have any general inquiries related to math, feel free to seek assistance on the platform math. It is important to note that if your query pertains to unusual outcomes encountered during floating-point calculations, it is advisable to consult the resource at math prior to seeking further help.

An algorithm designed to evenly distribute items among multiple arrays when the number of items is less than the number of arrays

Looking for an algorithm in PHP that can evenly distribute items across multiple arrays while skipping arrays if the number of items is less than the number of arrays. Here's a hypothetical scenario to illustrate my problem: Scenario: Imagine there ...

Ensure that 8 items out of the total of 12 are displayed within the viewport, with the remaining 4 items

I'm facing a challenge with my HTML layout that looks like this: <div class="container1"> <div class="item">Item 1</div> <div class="item">Item 2</div> ... etc </div> What I want to achieve is having a vari ...

The mysterious results of the 2F1 function in the scipy module

Why does hyp2f1 from scipy return 1? Shouldn't it be something else? https://i.stack.imgur.com/iEWIr.png Below is the code I used import numpy as np from scipy import special x = np.arange(0,2,0.01) y = special.hyp2f1(-1/2, 1/2, 2, -400/(1-8/9*np.c ...

Locate the smallest x and y values

What is the best way to determine the nearest point to 0,0 with a given array of X and Y coordinates? How can I then sort these points from the closest to the furthest distance from 0,0? <?php $array = array(array("x" => 10, ...

What is the best way to change integers within a list to type int()?

I am working on a function that can evaluate mathematical expressions within a string. My approach involves first converting the string into a list. Initially, I attempted to convert the entire array into an array of integers. However, I encountered an is ...

Performing a PHP select operation to extract a string for use in a mathematical problem, extracting data from a JSON decoded string, and subsequently

When passing the number 1 from my javascript file as $played = JSON decode, I find myself questioning whether my Select query is functioning correctly or if my math is simply incorrect. PHP is a relatively new concept to me, and I am unsure if I can rename ...

What is the method used by numpy to calculate an exponential?

Having recently explored this particular query, I am intrigued by the inner workings of what transpires when invoking np.exp: what precise mathematical or numerical methodology is employed to generate the values within the resulting array? As an illustrati ...

Customized slider in jQuery UI allowing users to select height using a scaled ruler

Currently, I am tackling a challenging math problem related to adjusting the height selector input. Essentially, I have implemented a jQuery UI slider for choosing a height. It operates in inches and ranges from 0 to 120 (equivalent to 10 feet in height). ...

Math.eval Support: The function may exhibit sporadic behavior, occasionally functioning properly and occasionally

Just dipping my toes into the coding world and currently working on a web app that's like a dashboard. I'm using node js, express, and mongoose. I've set up my schemas and collecting user data. There's some data I need to crunch number ...

Splitting JavaScript Arrays: Exploring Efficient Division

I'm attempting to develop a recursive function that divides an array in half until it only consists of lengths of 3 and 2. After dividing, I want to neatly organize all the new arrays into another array. My idea is to find a way to determine the number of ...

Discovering an elusive number using the fewest attempts possible

I'm currently working on a Python script to efficiently find an unknown number with the fewest attempts possible. The only information I have about the mystery number is that it is less than 10000. Each time I input the wrong guess, I receive an "error" ...

When using Math.floor(Math.random() * val.length), the result will be a letter rather than a number

Looking to implement a feature where a different background image is displayed randomly upon page visit or refresh. Currently, specifying the images in an array like the example below works well, but I want to be able to pull from a folder. $(document).r ...

Determine the percentage using jQuery by considering various factors

I am facing an issue with the following code snippet: <script type="application/javascript"> $(document).ready(function () { $("#market_value").on("change paste keyup", function() { var market_value = par ...

How can I obtain a rounded integer in Python?

My dilemma involves dividing the number 120 by 100 in Python. The result I am currently receiving is 1.2, however, I am seeking a solution to obtain only 2 (not 2.0) without importing any libraries. Is there anyone who can provide assistance with this? ...

Examining the overlap of two sets with two values each

Can you help me determine if there is an intersection between two arrays that have start and end values? You can find more information on this topic at this wikipedia page. Here are a couple of example cases: a = (10, float("inf")) b = (8, float("inf")) ...

"Error message: Invalid operation type(s) when subtracting a string and an integer," during the development of an age conversion tool

Can someone help figure out why this isn't working? (Click on the link for a screenshot) http://prntscr.com/5tbfos I would really appreciate it if someone could assist me in resolving this issue! Thanks so much, Ben Johnson ...

What is the reason behind allowing JavaScript to perform mathematical operations with a string type number?

let firstNum = 10; let secondNum = "10"; console.log(firstNum * secondNum); // Result: 100 console.log(secondNum * secondNum); // Result: 100 ...

What is the best way to utilize Python to solve and visualize a particular mathematical equation?

Hello, I am new to Python and have two questions that I hope you can help me solve. 1) How would I go about plotting all the points (x, y) that satisfy the following equation? y==11+(1+2x)((11x)/(5+10x))^((3y)/(3y-(5+x))) Given x>0 and y>0. 2) Now, let ...

Ways to combine X and Y velocities into a single velocity

Is there a way to combine the X and Y Velocity into a single Velocity without considering the angle? var velocityX = some value; var velocityY = some value; // Need to convert both X and Y velocities into one combined velocity ...

The strategic placement of the modulo operation within a programming algorithm

I've been grappling with a certain problem that ultimately boils down to calculating the value of https://i.stack.imgur.com/ovS3p.png (n+m-2 Combinations m-1). Here's what I have so far. In situations where the result exceeds 10^9+7, I must output my_ans ...

Loop through a collection of arrays that contain the same elements, and multiply each consecutive element by a specified value x

I've been diving into a challenging problem involving remarkable numbers, which are defined as A number that is equal to the sum of all its proper divisors -- provided one of them is negative. For instance, the proper divisors of 12 are 1, 2, 3, 4, 6, add ...

Is it possible to randomly generate an arithmetic operator and ensure its validity?

Attempting to generate a list of arithmetic operations randomly, taking into account the operators. The goal is to introduce randomness by adding parentheses as an operator on both sides. For example:- (2) + (51) = However, when I try to implement this in ...

What is the best method for discovering all possible partitions of list S into k subsets, some of which may be empty?

Given a list of unique elements, such as [1, 2], the goal is to split it into k=2 sublists. The objective is to generate all possible sublists: [ [ [1,2],[] ], [ [1],[2] ], [ [2],[1] ], [ [],[1,2] ] ] The task is then to split the list into 1<=k<=n ...

Utilize Javascript to create a function that organizes numbers in ascending order

Is there a way to modify this code so that the flip clock digits appear in ascending order rather than randomly? $( '.count' ).flip( Math.floor( Math.random() * 10 ) ); setInterval(function(){ $( '.count' ).flip( Math.floor( Math.rand ...

Calculate the degree measure of the angle between two points

class Point: def __init__(self, x: int, y: int): self.x: int = x self.y: int = y I have two points M and N, with their coordinates represented by integers (positive, zero, or negative). My goal is to calculate the angle in degrees betw ...

Performing mathematical operations in JavaScript, rounding to the nearest .05 increment with precision up to two

Apologies in advance. After reviewing multiple posts, it seems like the solution involves using the toFixed() method, but I'm struggling to implement it. $('.addsurcharge').click(function() { $('span.depositamount').text(function(i,v) { ...

Retrieve unique values for each day out of a total of 35 days using PHP

I am working on a project where I need to calculate the daily ROI value for 35 days and save it in the user table. Here is the code snippet that I am using: $total_days = 35; $total_amount = 200; $arr = array(); for($i = 0; $i < $total_days; ++$i) { ...

Combining two extremely large numbers encoded as base64 strings

Lately, I've been utilizing base64 strings in php to represent my enormous numbers. I'm curious if there is a library or built-in system that can assist me in performing arithmetic operations like addition, subtraction, multiplication, and division with ...

Substitute all instances of numbers in scientific notation with standard numbers

I need help handling a large XML string containing decimal values in both regular and scientific notation. I am looking for a way to convert all exponential values to regular notation directly. So far, I have developed the following Regex pattern that ide ...

Only the initial value is being processed in the for loop using Javascript

I am having issues trying to sum the values within a for loop sourced from my Django database using JavaScript. Currently, when I iterate through the loop, only the first value in the array is returned. I need assistance in finding a solution that allows ...

Obtaining every possible combination from a database table using different values

Assume we have a basic DB-table named tab set up in MySQL with the following structure: CREATE TABLE `tab` ( `id` int(11) NOT NULL AUTO_INCREMENT, `val` int(11) DEFAULT NULL, `altval` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ); The table is then popul ...

Calculate the total number of unique prime numbers in a given array using Python

Consider the following scenario - You are provided with an array A containing N integers. Let's say G represents the product of all elements in A. The task is to determine the count of distinct prime divisors of G. Example - Input : A = 1, 2, 3, 4 Output ...

Using numbers such as 1, 2, 3 in Python to execute various sections of code - a guide

Just starting out on stack overflow and diving into Python with version 3.8.2. Currently experimenting with coding on . Working on a math solver that uses specific formulas, including print functions, input functions, and integer variables. The goal is t ...

Inquire with the user for an integer greater than 500. Compute the square root of the entered number and present the result rounded to two decimal places

I need to create a program that prompts the user to input an integer greater than 500. Then, I must calculate the square root of that number and display it with two decimal places. Here is what I have so far: import math number = int(input("Please enter a ...

What makes TS unsafe when using unary arithmetic operations, while remaining safe in binary operations?

When it comes to arithmetic, there is a certain truth that holds: if 'a' is any positive real number, then: -a = a*(-1) The Typescript compiler appears to have trouble reproducing arithmetic rules in a type-safe manner. For example: (I) Working as expec ...

Is there a way to perform mathematical operations such as 5log(7.5/2) using PHP programming language?

I attempted to solve it using the equation 5*log(7.5/2), but I'm starting to doubt if that's the correct approach. Could someone please provide guidance on how to correctly tackle this problem? ...

Breaking down a large JSON array into smaller chunks and spreading them across multiple files using PHP pagination to manage the

Dealing with a large file containing over 45,000 arrays can be challenging, especially on a live server with high traffic. To address this issue, I used the array_chunk($array, 1000) function to divide the arrays into 46 files. Now, my goal is to access a ...

Looking for a PHP program that utilizes the Shunting Yard algorithm to interpret and evaluate a mathematical expression in string format, ultimately producing a boolean result

I am in search of a solution that can interpret a string in php and execute basic math operations, providing a boolean result to determine if the expression is true or false. For instance: Sue inputs "3*{mysalary}/9=10000" PHP breaks this down into two ...

Tips for arranging elements in proper order following a rotation

Having trouble aligning rotated divs? Let's say we rotate .straight by 30deg, and now we want to find the new offset coordinates of its bottom right corner. This way, we can perfectly match up the bottom left corners of .curve with this new coordinate ...

I am curious about how to input a new location into a GPS system

Can anyone advise on how to add noise to a GPS point (latitude and longitude) using a Gaussian distribution with a radius of 10m in Python? ...

The Python function is functional when dealing with individual values, however, it is not compatible with vectors. The error message it throws is "only size-1 arrays can be converted to Python scalars

As a beginner in Python with some experience in Matlab, I am attempting to create a function for the Gaussian kernel with a mean of 0. Here is the code I have written: import numpy as np import math def GaussainKernel(x,sigma): xx = np.array(x) re ...

The random number generator in TypeScript not functioning as expected

I have a simple question that I can't seem to find the answer to because I struggle with math. I have a formula for generating a random number. numRandomed: any; constructor(public navCtrl: NavController, public navParams: NavParams) { } public ...

Tips for using Jquery to round up currency values

Is there a way to round up various currencies using jQuery? I have a specific requirement: 10.30 → 10 //Round down if below .5 10.60 → 11 //Round up if after .5 849.95 → 850 1,022.20 → 1022 ...

A method for pinpointing the subset of numbers that shares the least amount of elements within a group of equivalent numbers

Suppose I have a dataset that is much larger, containing lists of 4 numbers selected from the range 0 to 9: (1,2,3,4) (3,5,6,0) (4,5,7,9) (1,2,7,8) If I want to identify the list(s) of numbers with the fewest matches against this collection, is there ...

the gravitational center of every cell within an N-dimensional grid of right angles

In a multi-dimensional rectilinear grid, the edges in each dimension 'i' are defined as x_i = {x[i, 0], x[i,1], ..., x[i, Ni-1], x[i, Ni]}, with 'N_i' edges in that specific dimension. A density y of shape (N0, N1, ... Ni, ... Nn-1) is ...

Simple JavaScript numeric input field

Hey there, I'm a beginner learning JavaScript. I'm currently working on creating a program that adds numbers input through text fields. If you want to check out the HTML code, visit this link on JS Fiddle: http://jsfiddle.net/fCXMt/ My question is, how ...

Determining the length and angle of a shadow using X and Y coordinates

I'm currently tackling the task of extracting data from a file generated by a software program that has the ability to add a shadow effect to text. The user interface allows you to specify an angle, length, and radius for this shadow. https://i.stack ...

Error: The `math.sqrt()` function encountered a math domain error due to an invalid value

Can anyone help me with a program to check for Herone Triangle in the specified range of tries to max_tries? I'm having trouble with the math.sqrt() function. This is the code I have so far: import math max_tries = 10000 tries = 1 half_perimeter = ((trie ...

A method for performing precise division on numbers in JavaScript, allowing for a specific precision level (such as 28 decimal places)

I've searched extensively for a library that can handle division operations with more than 19 decimal places, but to no avail. Despite trying popular libraries like exact-math, decimal.js, and bignumber.js, I have not found a solution. How would you appro ...

Strange division patterns within Python

Feeling completely perplexed by a seemingly simple issue. In a vast program, there are two objects called Thing and Stuff situated on a grid, and I am struggling to determine the angle between them in relation to the y-axis. The math.atan function requires ...

Formula for determining the slider's span

I recently created a range slider using Vue.js It has a minimum and maximum value, assumed to be percentages as it ranges from 0 to 100. My goal is to set the minimum value at $5,000 and the maximum at $200,000, However, I struggle with math and need th ...

What is the method for determining the level based on the provided experience points?

I've created a formula that can calculate experience based on specific levels and another formula that calculates the level based on given experience. However, there seems to be an issue with the second function as it is not returning the expected val ...

Performing matrix summation and multiplication using the numpy library

It has been quite a while since I last delved into the world of matrix math, almost two decades to be exact. A specific point exists in space: point1 = (x, y) Alongside this point is a scaler value: scaler = 0.5 An intricate transformational matrix ...