math

c++ convert a fractional part of a number into integer

纵饮孤独 提交于 2020-01-14 08:51:07
问题 I needed to convert a fractional part of a number into integer without a comma, for example I have 3.35 I want to get just 35 part without zero or a comma, Because I used the modf() function to extract the the fractional part but it gives me a 0.35 if there is any way to do that or to filter the '0.' part I will be very grateful if you show me how with the smaller code possible, 回答1: A bit more efficient than converting to a string and back again: int fractional_part_as_int(double number, int

Approximation of a common divisor closest to some value?

烂漫一生 提交于 2020-01-14 08:08:50
问题 Say we have two numbers (not necessarily integers) x1 and x2 . Say, the user inputs a number y . What I want to find, is a number y' close to y so that x1 % y' and x2 % y' are very small (smaller than 0.02 , for example, but lets call this number LIMIT ). In other words, I don't need an optimal algorithm, but a good approximation. I thank you all for your time and effort, that's really kind! Let me explain what the problem is in my application : say, a screen size is given, with a width of

Java: BigDecimal and Double.NaN

∥☆過路亽.° 提交于 2020-01-14 08:05:51
问题 I am trying to execute following code: import java.math.*; public class HelloWorld{ public static void main(String []args){ System.out.println(BigDecimal.valueOf(Double.NaN)); } } And reasonably, I am getting: Exception in thread "main" java.lang.NumberFormatException at java.math.BigDecimal.<init>(BigDecimal.java:470) at java.math.BigDecimal.<init>(BigDecimal.java:739) at java.math.BigDecimal.valueOf(BigDecimal.java:1069) at HelloWorld.main(HelloWorld.java:6) Is there a way to represent

Java: BigDecimal and Double.NaN

做~自己de王妃 提交于 2020-01-14 08:05:13
问题 I am trying to execute following code: import java.math.*; public class HelloWorld{ public static void main(String []args){ System.out.println(BigDecimal.valueOf(Double.NaN)); } } And reasonably, I am getting: Exception in thread "main" java.lang.NumberFormatException at java.math.BigDecimal.<init>(BigDecimal.java:470) at java.math.BigDecimal.<init>(BigDecimal.java:739) at java.math.BigDecimal.valueOf(BigDecimal.java:1069) at HelloWorld.main(HelloWorld.java:6) Is there a way to represent

Average of two angles with wrap around [duplicate]

拟墨画扇 提交于 2020-01-14 07:13:35
问题 This question already has answers here : Closed 10 years ago . Possible Duplicate: How do you calculate the average of a set of angles? I have two angles, a=20 degrees and b=350 degrees. The average of those two angles are 185 degrees. However, if we consider that the maximum angle is 360 degrees and allows for wrap around, one could see that 5 degrees is a closer average. I'm having troubles coming up with a good formula to handle that wrap around when calculating average. Anyone got any

Average of two angles with wrap around [duplicate]

 ̄綄美尐妖づ 提交于 2020-01-14 07:11:05
问题 This question already has answers here : Closed 10 years ago . Possible Duplicate: How do you calculate the average of a set of angles? I have two angles, a=20 degrees and b=350 degrees. The average of those two angles are 185 degrees. However, if we consider that the maximum angle is 360 degrees and allows for wrap around, one could see that 5 degrees is a closer average. I'm having troubles coming up with a good formula to handle that wrap around when calculating average. Anyone got any

constructing a square matrix of edge N, and its element should not be same across same row and column

江枫思渺然 提交于 2020-01-14 07:07:44
问题 So, I was constructing a matrix (square) of length N, its element i should between 1 <= i < 2 * N Each element should be between 1 to 2 * N - 1 for each i and j (1 <= i <= N and 1 <= j < 2 * N ) the j element should appear in i th row / i column for any N if the desired matrix is not possible we have print -1; Which means for N = 2 We could get matrix as - 1 2 3 1 As we can see for 1st row and column we can get 1 , 2 , 3. and for 2nd row and column we get 1, 2, 3 Another example : for N = 4 1

scipy.optimize.curve_fit a definite integral function with scipy.integrate.quad

久未见 提交于 2020-01-14 07:04:13
问题 If I have a function that the independent variable is the upper limit of an definite integral of a mathematical model. This mathematical model has the parameters I want to do regression. This mathematical model is nonlinear and can be complicated. How can I solve this? if the output of my function is then be processed, can it be curve_fit? There is a simplified case import scipy.optimize as sp from scipy.integrate import quad import numpy as np number = 100 def f(x,a,b,c): return 500*a*x+b*c

scipy.optimize.curve_fit a definite integral function with scipy.integrate.quad

谁说我不能喝 提交于 2020-01-14 07:03:44
问题 If I have a function that the independent variable is the upper limit of an definite integral of a mathematical model. This mathematical model has the parameters I want to do regression. This mathematical model is nonlinear and can be complicated. How can I solve this? if the output of my function is then be processed, can it be curve_fit? There is a simplified case import scipy.optimize as sp from scipy.integrate import quad import numpy as np number = 100 def f(x,a,b,c): return 500*a*x+b*c

Moving the mouse along a diagonal line

冷暖自知 提交于 2020-01-14 06:52:27
问题 What kind of math algorithm could I use to calculate the path to move a mouse? I simply want to have this type of function: animateMouseDiag(int X, int Y){ //Move mouse 1 step towards goal, for loop most likely, from the current Mouse.Position Thread.Sleep(1); } For example, if I give it animateMouseDiag(100,300), it would move the mouse 100 to the right and 300 down, but diagonally, not right-then-down in an 'L'. Similarly, if I gave it (-50,-200) it would move it to those relative