I wanna write a neat code to compute the shortest distance between a point and any line segments in any directions. I understand that in many cases the shortest distance would be a line perpendicular from the point to the line segment and in some cas

I am reading data from a gyroscope (MPU6050). It gives me the angular velocity. I am trying to integrate this data in order to know the angle of the gyroscope. The way I do this is by multiplying the read data with the elapsed time and continuously a

this is my program I hope you understand what I am trying to do. if (primeNum = int) { Console.WriteLine(" the number entered is not prime "); } Try this program: using System; using System.Collections.Generic; using System.Linq; using System.Te

I've been familiar with the famous question of implementing multiplication using addition, or exponentiation using multiplication, using algorithms of looping or bit-shifting and adding shifted bit groups combos. Now, I wondered if there is any way t

Background I am making a function that receives a positive number and then rounds the number to the closest integer bellow it. I have been using Math.floor, but recently I discovered Math.trunc. I am aware that both will return the same value, given

In .NET, why does System.Math.Round(27.2351, 2, MidpointRounding.AwayFromZero) yield 27.24 instead of 27.23? Third digit is 5 so we check for 4th digit that is 1 less than 5 so result should be 27.23 Is there any way to get this result. See My proble

I am solving a coding question from leetcode in which we are supposed to Count the number of prime numbers less than a non-negative number, n. This is my solution: class Solution(object): def isPrime(self, Number): return 2 in [Number, 2**Number % Nu

numpy has three different functions which seem like they can be used for the same things --- except that numpy.maximum can only be used element-wise, while numpy.max and numpy.amax can be used on particular axes, or all elements. Why is there more th

Let's give expressions some names: x+3 = x+1+1+1 // lvl 1 x*3 = x+x+x // lvl 2 x^3 = x*x*x // lvl 3 What would be the mathematical term / real name / topic for lvls after 3? Like: x (lvl 4 operation) 3 = x^x^x x (lvl 5 operation) 3 = x(lvl 4 operatio

This is a problem on a programming judge. In resume, the statement is the following : Black holes have an overwhelming gravity, such that the nearest stars begin spinning around them (Example). Every affected star keeps constant angular velocity and

I have an array nMean_2 (1-by-16320), I want to divide it into 255 equal parts and store it in matrix (64-by-255) mean2Electro = zeros(64,255); r=1; for z=1:64 mean2Electro(z,:)= nMean_2(r:((z*256)-1)) r= z*256; end But, I am getting an error: ??? Su

The same C code with the math sin() function runs much slower when I compile my program on ARMv7 compared to what I get on Windows. I'm compiling with -O2 -Wall -Wextra -mfpu=neon -mtune=cortex-a9 -march=armv7 -std=c++11 and my gcc is gcc (Ubuntu/Lin

I've made a BOMDAS calculator in C++ that uses doubles. Whenever I input an expression like 1000000000000000000000*1000000000000000000000 I get a result like 1000000000000000000004341624882808674582528.000000. I suspect it has something to do with fl

Yesterday one of my friend came with a problem, asking me to find the solution. The problem I have a matrix(n x m). I need to find out the least sum what I can produce from those matrix element. The condition is : Counting should only start from the

The code below is able to determine the correct sequence up to a point namely 70 using the data type unsigned long long. I know the sequence can become large thus I mod 10,000 the results. I want to determine the nth term for 10,000 using the best da

I understand that all of the math functions in java are built in. But I was wondering out of curiosity how Math.min() actually works? I checked the java documentation and couldn't find anything to help me. I'm quite new to java.int public static int

I would like to find the greatest common divisor using JavaScript. Anyone done that before and willing to share?Here is a recursive solution. var gcd = function(a, b) { if ( ! b) { return a; } return gcd(b, a % b); }; Our base case is when b is equal

I am currently studying for my final in algorithms. This is not a homework problem and comes from an old final exam. Show that f(n) = 4logn + log log n is big theta of logn. It is obvious that log log n is considerably smaller than log n and thus ins

I am a little confused about rounding to nearest in floating point arithmetic. Let a, b, and c be normalized double precision floating point numbers. Is it true that a+b=b+a where + is correctly rounded to nearest floating point addition? My initial

I have a (sampled) set of uncalibrated values (x) coming from a device and a set of what they should be (y). I'm looking to find/estimate the cubic polynomial y=ax^3 + bx^2 + cx + d that maps any x to y. So I think what I need to do is Polynomial Reg

I am having some issues on how to solve recurrence relations. T(n) = T(n/2) + log2(n), T(1) = 1, where n is a power of 2 This is a homework problem, so don't just give me the answer. I was just wondering how to start the problem. In class we went ove

I have a source value that I need to apply multiple percentages, but at the same time, and the percentages have to take into account the other percentages. Take for instance: Value = 100 Percentage1 = 10% Percentage2 = 15% Percentage3 = 17% I need to

Even though I read a number of articles that say that mostly 2's complement is used to represent the negative numbers in a signed integer and that that is the best method, However for some reason I have this (below) stuck in my head and can't get rid

As part of a calculator app, I am trying to implement uses with sigma notation. However, the result it prints out is always a decimal, and the rest isn't important. I simply want to change the decimal to a fraction. I already have the reduce function

I have a vector v1 (suppose v1= a1,b2,c1) and this v1 passes through the point x1,y1,z1. Now I need a second vector, v2 which is perpendicular to the v1. Suppose that v2 is passing through the second point x2,y2,z2. However, my final goal is to find

How can i make a smooth circular orbit at a constant speed using pygame? How would i calculate x, y on a circle?Rotating about the 2d point center with the given radius and speed. The parameter t is the time in units of seconds. def circular_orbit(ce

What is the most efficient way to calculate the least common multiple of two integers? I just came up with this, but it definitely leaves something to be desired. int n=7, m=4, n1=n, m1=m; while( m1 != n1 ){ if( m1 > n1 ) n1 += n; else m1 += m; } Sys

I have a program written in C# and some parts are writing in native C/C++. I use doubles to calculate some values and sometimes the result is wrong because of too small precision. After some investigation i figured out that someone is setting the flo

How can I find prime numbers through bit operations in C++?Try implementing a prime sieve using a bitset. The algorithm only needs to store whether a certain number is a prime or not. One bit is sufficient for that.

I need a function which takes a line (known by its coordinates) and return a line with same angle, but limited to certain length. My code gives correct values only when the line is turned 'right' (proven only empirically, sorry). Am I missing somethi