Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [python]

For mathematical questions about Python; questions purely about the language, syntax, or runtime errors are off-topic here and would likely be better received on Stack Overflow.

0
votes
2answers
29 views

How can I type this into a calculator?

In a textbook I am asked to calculate an expression using a calculator: $$\frac{1}{2}\ln\left(e^{22}\right)$$ I tried using: 0.5*log(exp**22) This returned an ...
0
votes
1answer
11 views

Computing eigenvectors from a transition matrix

I have a 21x21 transition matrix modeling the population of a species, and I'm trying to find the long term population proportions of the states. To do this, I'm using numpy. I found the dominant ...
0
votes
0answers
30 views

Find taxicab numbers in less than $O(n^2)$ time with number theory into consideration

If seen as an algorithm question, the taxicab numbers can be found in $O(N^2)$. However, I am wondering are there any improvement to get this numbers with less time complexity considering number ...
1
vote
0answers
12 views

BFGS: Wolfe conditions and Algorithm error on absolute values

I debated whether to put this in SO or Mathematics but the problem I suspect is more a mathematical question rather than a programming one. I have a simple objective function: $$f(x) = |x_0| + |x_1| ...
1
vote
1answer
30 views

Newton's method with Gaussian elimination

Implement Newton's method for a system of nonlinear equations $f(x) = 0$, where $f = (f^1,...,f^n)^T = 0$ and $x = (x^1,...,x^n)^T$. Both the function $f$ and the Jacobian $J$ are given as lambda ...
1
vote
1answer
17 views

Finding the y-coordinate of the intersection of two functions when all x-coordinates are unknown

Part 1 I have 2 lines defined by 4 points in a plane: $\overline{(x_1, y_1), (x_2, y_2)}$ and $\overline{(x_3, y_3), (x_4, y_4)}$. I would like to find the $y$-coordinate of the intersection point ...
0
votes
0answers
17 views

How to calculate a weighted probability distribution?

Wikipedia explains a key step in the KMeans++ algorithm as ... "Choose one new data point at random as a new center, using a weighted probability distribution where a point x is chosen with ...
-1
votes
0answers
15 views

Formula for realized gain with existing position?

I'm trying to calculate the absolute gain (USD) of a trade while there is an existing position. Idea is that realized gain can only happen if position is + (e.g. long position) and trade is - (short ...
1
vote
0answers
35 views

Connecting Orbits (Heteroclinic Orbits) Between Fixed Points on a Phase Portrait

I was given a ODE system in which I'm needing to solve several things. The ODE is: $v' = v(v-1) + \frac{5}{3}(e - \frac{3}{50}v)$ $e' = v[-\frac{(v-1)^2}{2} + e - \frac{3}{50} + \frac{1}{10}(v-1)]$ ...
10
votes
3answers
2k views

Why is a simulation of a probability experiment off by a factor of 10?

From a university homework assignment: There are $8$ numbered cells and $12$ indistinct balls. All $12$ balls are randomly divided between all of the $8$ cells. What is the probability that there is ...
1
vote
1answer
63 views

SVD and best rank-k

In the following code I am using Python's pillow/PIL library. I have successfully been able to read in an image file and store it as a matrix, access the red, blue, green channel which is an unsigned ...
2
votes
1answer
83 views

How to convert Euler angles to Quaternions and get the same Euler angles back from Quaternions?

I am rotating n 3D shape using Euler angles in the order of XYZ meaning that the object is first rotated along the X axis, then Y...
0
votes
0answers
18 views

Stochastic Differential Equation and Runge-Kutta

I have to solve the Black-Scholes equation, $\textrm{d}X\left(t\right)=\lambda X\left(t\right)\textrm{d}t+\mu X\left(t\right)\textrm{d}W\left(t\right),$ by making use of a RK method (in Python). ...
0
votes
1answer
38 views

How to randomly draw Quaternions within a specific range of Euler angles for rotation?

I am pretty new to Quaternions so please bear with me. I want to draw random Quaternion samples so that their Euler angle equivalent would range within [-30, +30] ...
8
votes
4answers
85 views

How many non-diagonalizable $2\times 2$ matrices are there with all entries single-digit strictly positive integers?

I'd like to know how many non-diagonalizable size 2 matrices there are with integer coefficient between 1 and 9. I built a python program which counts the non-diagonalizable matrices with such ...
0
votes
0answers
19 views

System of linear equations with unknown multidimensional matrix

How to solve systems of linear equations with multidimensional matrices? I have to solve the system like this: $$ \sum_{i'=1}^{L}\sum_{k'=1}^{n} a_{i-i',k'} x_{i',j,k'} = a_{i,j}, $$ $L+1\leq i\leq T$...
0
votes
1answer
20 views

SOR iteration in numerical

In the following code I have made an SOR iteration in python. I seem to be getting the wrong output. It seems to be just outputting the b array when it should be solving the system. Is there something ...
0
votes
1answer
15 views

compute the infinity norm of the difference between the two solutions

In the following code I have been able to: Implement Gaussian elimination with no pivoting for a general square linear system. I have tested it by solving Ax=b, where A is a random 100x100 matrix and ...
1
vote
0answers
21 views

Difference between mathematical interpolation and numerical interpolation?

I have a data set of points. This data is not of full points. Instead, I have to generate a python code using tck = interpolate.bisplrep(xx, yy, zz, s=0) to ...
0
votes
0answers
46 views

Weird visual result for MLE of normal distribution

I am trying to visualize the log likelihood estimator for normal distribution via python but in vain. I am not sure if its a python issue or formuala issue in the code. Can you kindly have a look? ...
1
vote
1answer
31 views

relative error in numerical methods

I have a question about a task I am trying to complete. I have created a code to produce a determinant of a $100\times 100$ matrix. Now I want to compute the relative error between my solution and the ...
-1
votes
1answer
96 views

Gaussian elimination in numerical

In the following code I have implemented Gaussian elimination without partial pivoting for a general square linear system Ax = b. However I am looking for some help with implementing the following ...
0
votes
0answers
96 views

Solving system of inequalities with 3 variables in python

I'm trying to solve a system of multivariables with inequalities in python. I have this set of equations: ...
0
votes
0answers
40 views

How do you choose a suitable integration method?

I'm trying to solve a system of 20 coupled differential equations through computing. These equations exhibit strong oscillatory solutions over millions of years. I have been reading around, however I ...
0
votes
0answers
38 views

Transfer of source code with lists of tuples into mathematical notation for scientific work

At present I am writing a scientific paper and have problems bringing source code into mathematical form. I have a time series that I present in Python as a list of tuples. For example: ...
0
votes
2answers
76 views

How to calculate the intersection point between a straight and a triangle (in python)?

Introduction: I try to program a small ray tracer application in which I have planed to reflect a ray on the surface of a triangle like the following sketches shows: Conditions: Given are the ...
1
vote
1answer
55 views

$\frac{\sqrt{9+x}{-3}}{x}$ for $x = 10^{-n}$, $n \in \{4,…,13\}$ and interpret the observations

I am looking for some help with the following question. I am really stuck! I am trying to use python to evaluate $$\frac{\sqrt{9+x}{-3}}{x}$$ for $x = 10^{-n}$, $n \in \{4,...,13\}$ and interpret ...
0
votes
1answer
51 views

Why am I unable to observe $O(n^2)$ time complexity with Bubble Sort?

I am seeking to confirm that Bubble Sort has an average performance of $O(n^2)$ I wrote the following code in Python. bubble_sort takes a list of size $n$ and ...
0
votes
0answers
34 views

Euler Poisson integration problem

I wish to calculate the follwoing integral: $$\frac{\intop_c^\infty x^me^{-\frac{1}{2}(x-a)^2}dx}{\intop_0^\infty x^me^{-\frac{1}{2}x^2}dx}$$ for a given $a,c\in\mathbb{R}$ and a given $m\in\mathbb{Z^+...
2
votes
1answer
135 views

Why Sampling without replacement gives better CI performance?

I was learning confidence intervals progressing slowly with few hiccups 1, 2, and wrapping up while found few more issues, one of which I have detailed here. Requesting your kind help. I created a ...
1
vote
1answer
122 views

Points inside a 3D rectangle [duplicate]

my task is to find, and mark, all the points from a point cloud that are inside a 3D rectangle. I have the coordinates of all the 8 vertices. Is there a mathematical formula which I can use? To be ...
0
votes
1answer
30 views

How to export the output to excel sheet in python 3? [closed]

I have the following python code which gives two sets of numerical results. I want to use the output for my computation. After each code run I copy the output manually to excel sheet that takes a lot ...
0
votes
0answers
41 views

Solving coupled differential equations with initial values

Hello fellow stackexchange users, as the title suggests I'm kind of stuck with a numerical problem, I need to solve the following 3 coupled differential equations numerically: These equations shall ...
0
votes
0answers
51 views

Fista implementation

I´m trying to extract heart rate from NIR video data by implementing the algorithm explained in http://openaccess.thecvf.com/content_cvpr_2018_workshops/papers/w27/...
2
votes
1answer
67 views

Fibonacci Coding Inductive Proof

Prove by induction on $n$, that every positive integer has a Fibonacci representation, as in the Fibonacci code representation. So, while I understand the premise behind the Fibonacci coding, and I ...
0
votes
1answer
92 views

Confidence Intervals - Inconsistent Statistical Results

After my last SE question on confidence Intervals here, which clarified the intuition, I tried then to verify statistical results if they are convincingly compliant with theory. I started with CI for ...
1
vote
0answers
25 views

How to obtain $x$ and $y$ coordinates from curvature data

I want to visualize points that are given as curvature data (arclength along the path,curvature or radius) e.g. $$ \begin{array} {ccc} \hline \text{arclength} & \text{curvature} & \text{...
0
votes
0answers
37 views

Why Sampling distribution not skewed when np < 10 and nq < 10?

My aim is to study "Sample distributions" via simulations convincing myself of the outcomes. After struggling with questions here, here and here, finally I hope am somewhat getting my head around it....
3
votes
0answers
33 views

Finding Large Pseudoprimes with a Computer

I'm reading the book Prime and Programming and I'm stuck on one of the computer exercises. I'm checking for Fermat Pseudoprimes and I've written a program that works for reasonably small numbers, e.g....
1
vote
2answers
63 views

Finding the “simplest” rotation transform

I am trying to undo some simple rotation errors of my sensor by tracking a reference plane. I am using the following accepted solution: Calculate Rotation Matrix to align Vector A to Vector B in 3d? I ...
0
votes
1answer
20 views

Sample Distribution Simulation not resulting in Normal

I was trying to simulate "Sampling Distribution of Sample Proportions" using Python. I tried with a Bernoulli Variable as in example here The crux is that, out of large number of gumballs, we have ...
0
votes
1answer
52 views

What is the difference between the following two tests: w.isupper () and not w.islower ()?

It's a question at the crossroads between computing and set theory I just immersed myself in the Python documentation to answer this question Let say $w$ is a string. What is the difference ...
1
vote
1answer
507 views

Python Compute Jacobian numerically

Hi I have a class with the purpose to solve system of Differential equations, this class contains a class named Rhs (right hand side) that contains all the feature of the differential problem: ...
0
votes
1answer
161 views

Python Solving simultaneous equations with numpy

I wanted to solve a triplet of simultaneous equations with python. I managed to convert the equations into matrix form below: For example the first line of the equation would be ...
1
vote
1answer
105 views

Computational Challenge of Multivariate Integration in Sympy

I am creating a piecewise linear approximation for the following equation: $$W = \frac{\theta \left(k \rho\right)^{k}}{2 k^{2}k! \rho \left( 1- \rho\right)^{2} \left(\frac{\left(k \rho\right)^{k}}{\...
1
vote
2answers
93 views

Which eigenvectors do MATLAB/numpy display when eigenvalues are repeated [closed]

When a matrix has repeated eigenvalues, which eigenvectors do linear algebra libraries (particularly MATLAB/numpy) display? For example, in MATLAB, I tried ...
1
vote
0answers
102 views

Calculating the probability of winning a game of Rainbow Six Siege

I'm currently developing an application in Python that calculates the probability of winning a game of Rainbow Six Siege based on the skill level of the players in the game. Siege is a 5 vs. 5 ...
0
votes
2answers
38 views

Calculating the Probability of a Subset

This is my first time facing a topic in stochastics. My Problem: i have a total set of 7000 Numbers and a fixed subset containing 450 Numbers. So let's assume Numbers from 1-450 are red, Numbers ...
0
votes
0answers
17 views

Finding gradient in vanilla RNN (constant components)

Introduction Given a vanilla RNN, defined below (capital letters=matrices, lowercase=column vectors): \begin{array}{l} {a_t} = W{h_{t - 1}} + U{x_t} + b\\ {h_t} = \tanh ({a_t})\\ {o_t} = V{h_t} + c\\ ...
2
votes
1answer
50 views

all the possible combinations to create triangles in a determined graph.

Im studying about graphs. I'm trying to get all the possible combinations to create triangles in a determined graph For example for the complete graph $K_5$, I want to get in sage or python the $10$ ...