math

Full factorization of polynomials over complexes with SymPy

亡梦爱人 提交于 2020-06-17 09:33:12
问题 I want to fully factorize a polynom, thus factorize it over complexes. SymPy provide factor to do it, but I’m very surprised that factorization is done only over integer roots, e.g. : >>> from sympy import * >>> z = symbols('z') >>> factor(z**2 - 1, z) (z - 1)*(z + 1) >>> factor(z**2 + 1, z) z**2 + 1 or >>> factor(2*z - 1, z) 2*z - 1 >>> factor(2*z - 1, z, extension=[Integer(1)/2]) 2*(z - 1/2) An answered question already exists : Factor to complex roots using sympy, and the solution given by

Cone to box collision

假装没事ソ 提交于 2020-06-16 17:27:10
问题 I'm looking to implement collision detection between a cone (With a round bottom. So it's basically a slice of a sphere) and a box. I'm not too fussed about it being AABB or OBB because transforming should be simple enough. Every solution I find uses a triangular cone but my cone is more of an "arc" that has an angle and distance. Is there a simple solution to doing this collision detection? Or is it a case of doing several types of tests? ie. something like getting intersection points on a

Cone to box collision

[亡魂溺海] 提交于 2020-06-16 17:25:28
问题 I'm looking to implement collision detection between a cone (With a round bottom. So it's basically a slice of a sphere) and a box. I'm not too fussed about it being AABB or OBB because transforming should be simple enough. Every solution I find uses a triangular cone but my cone is more of an "arc" that has an angle and distance. Is there a simple solution to doing this collision detection? Or is it a case of doing several types of tests? ie. something like getting intersection points on a

Calculating probability for FUNPROB

依然范特西╮ 提交于 2020-06-16 17:14:40
问题 Regarding - FUNPROB The solution is : int N, M; while(1) { scanf("%d %d", &N, &M); if (0 == N && 0 == M) break; if (N > M) printf("0.000000\n"); else { double res = (double) (M-N+1) / (M+1); printf("%.6f\n", res); } } My question is regarding line res = (M-N+1) / (M+1); How to arrive at the conclusion that the probability is calculated in this way ? 回答1: At first it is obvious that if N>M probability is zero. now I want to use indication on N to prove. consider M>0 I want to prove for every N

Using the inverse sec function in Python

孤人 提交于 2020-06-16 17:01:49
问题 I am creating a program that calculates the optimum angles to fire a projectile from a range of heights and a set initial velocity. Within the final equation I need to utilise, there is an inverse sec function present that is causing some troubles. I have imported math and attempted to use asec(whatever) however it seems math can not calculate inverse sec functions? I also understand that sec(x) = 1/cos(x) but when I sub 1/cos(x) into the equation instead and algebraically solve for x it

Using the inverse sec function in Python

天涯浪子 提交于 2020-06-16 17:01:40
问题 I am creating a program that calculates the optimum angles to fire a projectile from a range of heights and a set initial velocity. Within the final equation I need to utilise, there is an inverse sec function present that is causing some troubles. I have imported math and attempted to use asec(whatever) however it seems math can not calculate inverse sec functions? I also understand that sec(x) = 1/cos(x) but when I sub 1/cos(x) into the equation instead and algebraically solve for x it

Rock, Paper, Scissors. Determine win/loss/tie using math?

允我心安 提交于 2020-06-14 06:22:05
问题 So I was writing a rock paper scissors game when I came to writing this function: a is player one's move, b is player two's move. All I need to figure out is if player one won, lost, or tied. //rock=0, paper=1, scissors=2 processMove(a, b) { if(a == b) ties++; else { if(a==0 && b==2) wins++; else if(a==0 && b==1) losses++; else if(a==1 && b==2) losses++; else if(a==1 && b==0) wins++; else if(a==2 && b==1) wins++; else if(a==2 && b==0) losses++; } } My question is: What's the most elegant way

Java find intersection of two lines

百般思念 提交于 2020-06-12 07:26:26
问题 In Java, I have a class Line that has two variables : m and b , such that the line follows the formula mx + b . I have two such lines. How am I to find the x and y coordinates of the intersection of the two lines? (Assuming the slopes are different) Here is class Line : import java.awt.Graphics; import java.awt.Point; public final class Line { public final double m, b; public Line(double m, double b) { this.m = m; this.b = b; } public Point intersect(Line line) { double x = (this.b - line.b)

Python: Why do int.numerator and int.denominator exist?

孤街浪徒 提交于 2020-06-11 16:17:10
问题 int.numerator and int.denominator are a mystery to me. help(int.numerator) states: the numerator of a rational number in lowest terms But as far as I know, int is not a rational number. So why do these properties exist? 回答1: See http://docs.python.org/library/numbers.html - int ( numbers.Integral ) is a subtype of numbers.Rational . >>> import numbers >>> isinstance(1337, numbers.Integral) True >>> isinstance(1337, numbers.Rational) True >>> issubclass(numbers.Integral, numbers.Rational) True

Python: Why do int.numerator and int.denominator exist?

核能气质少年 提交于 2020-06-11 16:16:15
问题 int.numerator and int.denominator are a mystery to me. help(int.numerator) states: the numerator of a rational number in lowest terms But as far as I know, int is not a rational number. So why do these properties exist? 回答1: See http://docs.python.org/library/numbers.html - int ( numbers.Integral ) is a subtype of numbers.Rational . >>> import numbers >>> isinstance(1337, numbers.Integral) True >>> isinstance(1337, numbers.Rational) True >>> issubclass(numbers.Integral, numbers.Rational) True