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.

Filter by
Sorted by
Tagged with
0
votes
0answers
17 views

Hypothesis testing for anti proportional correlation

currently I am a bit in trouble regarding hypothesis testing - definitely my weakest area of math. I was studying it quite a lot in the past days but came across an problem that I don't know how to ...
0
votes
1answer
48 views

Imaginary number in quadratic equation [closed]

I am trying to write a python script to calculate quadratic equations, but I'm currently stuck with this. Can anyone help me and tell me, how i is supposed to be ...
1
vote
1answer
31 views

Implementing Bates distribution

I've been trying to plot the Bates distribution curve, The Bates distribution is the distribution of the mean of n independent standard uniform variates (from 0 to 1). (I worked on the interval [-1;1],...
-2
votes
0answers
12 views

Outputting ReduceLROnPlateau learning rates onto Tensor Board [closed]

I'm new to machine learning and I managed so far to find a way to have loss and accuracy show up on Tensor Board in the hopes of optimizing my model. However, I'm struggling to find anything online ...
-4
votes
0answers
26 views

How to remove this error [closed]

import csv filename = 'sitka_weather_07-2014.csv' with open(filename) as f: reader = csv.reader(f) header_row = next(reader) print(header_row) #part8 plotting data in a temperature chart import csv ...
1
vote
1answer
28 views

CVXPY constraints when dealing with block matrices! [closed]

I am trying to solve a robust optimization problem using CVXPY. I am new to this package and also a beginner of python. I don't know how to implement the constraint that makes a block decision ...
0
votes
0answers
25 views

In general when denominator(b) is greater that numerator(a), what is the procedure to calculate a %b? [closed]

How do we calculate 2 %3 ? In python when I executed following code, I got the answer as 8 instead of 16. ...
0
votes
0answers
34 views

Why are my y values incorrect? [closed]

Regarding a recent, more general/in depth question regarding some python code, I've done some further testing and searching and managed to boil it down to a now simpler question. I am trying to draw a ...
0
votes
0answers
60 views

Y values for graphing the arc of a circular segment when X is known.

I'm looking for some help checking that my math/reasoning is correct, with regards to calculating the y value for a corresponding and known x value. I am not confident with maths and my formulas have ...
0
votes
0answers
27 views

Getting the coordinates of a point travelling a vector

So I'm currently having a problem with a python game. Let's say we have a square with a side of $600$ pixels, let's call the top segment $AB$ and the bottom one $CD$. Now on the $AB$ segment there is ...
0
votes
1answer
32 views

How do you calculate the gradient of nll_loss(log_softmax(A*A*X*W0*W1)) w.r.t A?

I would like to know how I can calculate the gradient of null_loss(log_softmax(A*A*X*W0*W1)) w.r.t A. All A, X, W0, W1 are 2D ...
0
votes
1answer
46 views

Tolerance limit (interval) in python

I am trying to calculate the tolerance limit (interval) in python. As a reminder, the tolerance limits are: $$ \bar{x} \pm k s $$ where $\bar{x}$ is the sample mean and $s$ is the sample standard ...
1
vote
1answer
40 views

Plotting a linear system in python. [closed]

I am trying to plot a linear system from a book. Essentially it is just a quiver plot, which is otherwise known as a vector plot. The equation I am considering is \begin{equation} \dot{x} = y , \text{...
3
votes
3answers
108 views

Calculating quantiles of weighted array

First the proviso I'm only an aspiring mathematician. Secondly forgive how I've articulated this question in Python, but it is essentially a computational problem I'm looking to solve. I wonder if ...
1
vote
1answer
54 views

Solving the piecewise recurrence $f_n=f_{n-1}+f_{n-2}$ for $f_{n-1}$ even, and $f_n=f_{n-1}-3f_{n-2}$ for $f_{n-1}$ odd

How to solve this piecewise recurrence relation? $$ f_0=1\\ f_1=2\\ f_n = \begin{cases} f_{n-1}+\phantom{3}f_{n-2} & \text{if } f_{n-1} \text{ is even}\\ f_{n-1}-3f_{n-2} & \text{if } f_{n-1} \...
0
votes
1answer
32 views

How to use a use a quadratic optimization solver to have the weights of an efficient portfolio always positive?

I am trying to create a Simulated Portfolio Optimization based on Efficient Frontier on 50 stocks, which you can find the csv here. Thanks to LineAlg answer I know how to get the best portfolio but it ...
0
votes
2answers
22 views

Problem related to output in python programming (not gives expected result)

I'm very beginner at python. Given code gives error with output. Want to correct it. The mathematics behind the code is : Let denote $S_m(n)=1^m+2^m+...+n^m$ and denote $D_x(y)$ is sum of digits ...
-1
votes
2answers
40 views

Calculate specific angle between two lines

I have some problem with math today :) Could you tell me how should I calculate $P$ angle? I know first and last point of each line. So I have: ...
0
votes
1answer
17 views

Best way of forming n groups from a team of N people minimising overlap

I was recently asked the following seemingly simple question: What is the best way to partition a team of 12 people into groups of three, where the process is to be repeated 6 times? The solution ...
1
vote
1answer
69 views

Get the weights of porfolio variance given standard deviation

I am trying to create a Simulated Portfolio Optimization based on Efficient Frontier on 50 stocks, which you can find the csv here. Yet it already takes me several minutes to get a suboptimal solution:...
8
votes
2answers
231 views

Bouncing Bullet Problem

This is a problem that was presented to me through the google foobar challenge, but my time has since expired and they had decided that I did not complete the problem. I suspect a possible bug on ...
0
votes
0answers
24 views

How to determine the minimum number of grid points for successful FDM solution?

I am trying to solve the following BVP using the Finite Difference Method: $$y'' - y' + y = 0; \hspace{1em} y(0) = 1; \hspace{1em} y(10) = 5$$ I am using 3 points for each approximation. Using the 3-...
0
votes
1answer
54 views

Monty Hall Problem simulation - win lose rate doesn't seem to match the expected outcome [closed]

I created a simulation in Python for: A) A player who sticks with the chosen door B) A player who switches door after hosts opens a door without a price. For scenario A) I get 66% lose rate (33% win ...
0
votes
0answers
7 views

How do I apply cvxopt quadratic programming to solve this optimisation problem with 2 variables?

I want to solve the following convex optimisation problem using cvxopt in python. $$min_{\lambda, \mu} ||\mu_E - \mu||_2 $$ $$ s.t \sum_{\lambda=0}^{i-1}\lambda_j\mu^{(j)} = \mu $$ $$ \lambda \geq 0$$...
0
votes
0answers
24 views

Kolmogorov-Smirnov test Python

I just started learning statistics and need some help. I have ran the Kolmogorov-Smirnov test on two data sets using python. I used the code ...
1
vote
0answers
37 views

Convergence of the complex QR algorithm to Schur decomposition

I study the complex Schur decomposition of a complex matrix $A \in \mathbb{C}^{n \times n}$, that is: $$ A = U T U^H $$ where $T$ is upper-triangular (the eigenvalues of $A$ appear on its diagonal, ...
0
votes
0answers
30 views

QR algorithm with reduced Hessenberg form

Let $H$ be an upper Hessenberg matrix (see Wikipedia). I want to compute its complex Schur decomposition $H = U T U^H$ where $U^H = U^{-1}$ is unitary and $T$ is upper triangular matrix (the diagonal ...
0
votes
1answer
33 views

Bartels-Stewart Algorithm for the Complex case

Let $$ A X + X B = C $$ be the Sylvester equation when $A,B,C \in \mathbb{C}^{n \times n}$ are complex matrices. I want to solve it for $X$. Python's SciPy package $\texttt{solve_sylvester}$ function ...
1
vote
2answers
29 views

Efficient methods to calculate incomplete beta $B[a,b;x]$ for $b=0$

I am looking for an efficient numerical method (or a module) to calculate the incomplete $\beta-$function for $b=0$. e.g. https://www.wolframalpha.com/input/?i=incomplete+beta%5B4%2F5%2C1.5%2C0.0%5D+...
2
votes
1answer
23 views

Double integral of product of Bessel functions in Python

I would like to perform a numerical integral (in Python) of the form $$\displaystyle F_\nu(k) = \int_0^\infty dk' \ k' \int_0^\infty dr\ r \ f(k', r) \ J_\nu(k' r) \ J_\nu(k r),$$ where $J_\nu$ is ...
0
votes
0answers
25 views

Calculate the Probability of 2 Negatively Correlated Outcomes

How does one calculate the probabilities of 2 outcomes that are negatively correlated (A happens and B happens, A happens and B doesn't happen, B happens and A doesn't happen, neither A or B happen)? ...
1
vote
0answers
53 views

Why is $\cos(\cos(\cos(0))) = 0.739$ (with infinite $\cos()$)? [duplicate]

I was calculating the field of view for some telescopes, but then I came to this interesting expression: $$\cos(\cos(\cos(\cos(\cos(\cos(\cos(\cos(\cos(\cos(0))))))))))) = 0.739$$ where we have an ...
1
vote
1answer
59 views

Minimizing $\| x A - B\|_F^2$ With a Constraint

I have previously asked an optimization question Here. I will reiterate the question and simply add a constraint to it: I have 2 known grayscale images (256×256 matrices) $A$ and $B$ and want to find ...
0
votes
0answers
16 views

How to get the symbollic/analytic solution of 2nd order ODE system in python?

I'm sorry for my dummy question, I have 2nd order ODEs, they are double spring mass system model, my 1st eq is ...
0
votes
1answer
24 views

Computational complexity of solving Sylvester equation

In my case I assume $A,B,C,X \in \mathbb{C}^{n \times n}$ are $n \times n$ square matrices. The Sylvester equation (Wikipedia) is $$ A X + B X = C $$ and given $A,B,C$ we want to solve for $X \in \...
0
votes
1answer
35 views

How to calculate a two-sample z-test in python?

I want to calculate the pooled z-test in python, for two-samples. I generated 2D Pareto distributed data, I calculated their probabilities px and py. Now I need to calculate the p-pooled and the z ...
0
votes
0answers
18 views

Removing the rotational component in optical flow

I am working on a basic self driving algorithm using a monocular image sequence. For this, the optical flow between every two frames based on tracked keypoints is calculated (which is a vector for ...
0
votes
0answers
32 views

Taylor 2nd order approximation

Given the initial value $$y'=\dfrac 1 {t^2}-\dfrac yt-y^2, \\ 1 \le t \le 2, \\ y(1)=-1, \\ \text { exact }(t)=-1/t, h=0.05$$ I need to make a code to approximate the solution using Taylor method ...
0
votes
2answers
65 views

Solving ODE with Taylor method gives very wrong approximation

Can someone check this python code. I need to use Taylor's method of order 2 to approximate the solution to $$ y'= \frac1{x^2}-\frac{y}{x}-y^2,~~ 1\le x\le 2,~~ y(1)=-1 ~\text{ and }~ h=0.05. $$ it ...
0
votes
1answer
36 views

Newman algorithm yielding different result to what is given in his paper

Summary I am trying to implement Newman's algorithm for community detection, outlined in this paper. I am testing my implementation against one of the datasets used in that paper to benchmark the ...
-1
votes
1answer
46 views

RK4 for comet trajectory in Python [closed]

I'm trying to write a python program which simulates the trajectory of a comet using the Runge-Kutta 4th degree method. I'm given the acceleration formula $$\ddot x = -\frac{GM}{r^3} x$$ I believe ...
0
votes
0answers
8 views

Inconsistent formulas when solving recurrent equations using sympy.rsolve_poly

I am getting inconsistent formulas when using sympy.rsolve_poly to solve recurrent equations. This first piece of code solves $a(n+1) = a(n) + 4n^3$ with $a(0) = 0$...
0
votes
0answers
11 views

Why doesn't this Wiener process converge to the correct beta function?

I've attempted to simulate the following Wiener process in Python (code attached at end of post): $$dX = n(m-X)dt+\sqrt{\epsilon X(1-X)}dW$$ which I believe should converge to a beta process $p(X|\...
1
vote
1answer
32 views

Mathematical Operation (PEMDAS AND BODMAS)

I am learning Python and came across PEMDAS. Python uses PEMDAS to solve mathematical equations. But in lower classes like 5th or 6th we were taught BODMAS. I got confused and then made an equation ...
0
votes
0answers
15 views

The plane formed by the base of a cone transformed to x-y coordinates

I have a random 3-d walk where you can go either positive x,y,z by one step. After 1000 steps you most likely end up on concordant 333,333,333. I have a visual of 2000 trials.3d walks I want to plot ...
0
votes
0answers
133 views

High-dimensional optimization method's choice

I have a custom function from 72 parameters, which calls another software (MD-simulation) to compute the energy, which is to be minimized. One important note - this software has a built-in ...
6
votes
2answers
88 views

Doubling Point Formula of Elliptic Curve is Not Working

Let $E$ be an elliptic curve and a point $P = (x, y) \in E,$ from the duplication formula, the x-coordinate of $2P$ is - $$x_{(2P)}=(x^4-b_4*x^2-2*b_6*x-b_8)/(4*x^3+b_2*x^2+2*b_4*x+b_6)$$ The ...
1
vote
3answers
57 views

What is the function fsolve in python doing mathematically?

In the Python documentation for fsolve it says "Return the roots of the (non-linear) equations defined by func(x) = 0 given a starting estimate" f(x, *args). I wondered if anyone knew the mathematical ...
4
votes
4answers
145 views

Does this limit converge on e?

Playing around with some math in python today I came across what appears to be an interesting pattern: Starting at n=1 as n approaches positive infinity, take (n+1)^(n+2)/n^(n+1) and get a list of ...
0
votes
0answers
47 views

Solve a tedious system of equations which cannot be expressed in matrix form

I have two non-linear equations with only two variables which are tedious to solve. I'm having difficulty solving this system, is there anyway to input this into a solver? I tried solving it manually ...

1
2 3 4 5
11