Stack Exchange Network

Stack Exchange network consists of 175 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
1answer
37 views

Use matplotlib to plot the functions $y = x^3 + 3x^2 - x + 0.3\ $ and $y = \sin x$

I'm new to Python coding and wondered if someone could give me the coding to plot these two graphs on the same program. This is what I have so far, exactly as typed on Python, however I know that ...
0
votes
0answers
18 views

Binomial Probability Number of Trials Formula and Code

This is an interview question I've had. Your number space is between 0 to N. You can only draw M random samples from 0 to N (N >= M). How many times (T) would you need to draw from your number space ...
0
votes
0answers
9 views

How to vectorize/matricize multivariate Gaussian PDF for more efficient computation?

Context: I was recently implementing (in Python) the Expectation-Maximization (EM) algorithm for Gaussian mixture models, and part of that process involves computing the Gaussian PDF for various ...
-1
votes
0answers
44 views

How can I form in python this matrix to the corresponding graph?

im working in graph theory and sagemath or python. for prove that $R(3,3)=6$ is necessary to find a counterexample of a graph where it has neither a triangle monochromatic red nor a $K_3$ blue, for ...
1
vote
2answers
55 views

Hackerrank matchstick experiment

The problem is regarding probability. The problem is given in detail here. In an $m \times n$ grid, $2mn -m -n$ matchsticks are placed at the inner boundaries between squares on the grid. We can ...
-1
votes
0answers
10 views

Facing error - catalyst.utils while running algorithm…in pycharm [on hold]

from catalyst.utils.run_algo import run_algorithm def initialize(context): context.bittrex=context.exchanges['bitfinex'] context.poloniex = context.exchanges['poloniex'] ...
0
votes
0answers
17 views

Find boundaries to separate peaks in a 3D plot using matlab or python

Could you tell me how to find boundaries to separate the peaks in the 3D plot below? Ideally, the boundaries are at the local minimum. Peaks can be generated using Gaussian distributions with some ...
2
votes
0answers
38 views

How can I calculate Feigenbaum's constant?

So I am trying to calculate Feigenbaum's constant for the logistic map: $$ x_{n+1} = 4 \lambda x_n (1-x_n) $$ I am writing this through python and the main pieces I have for my code that are relevant ...
0
votes
0answers
11 views

quadratic bezier to parabola matrix equation

I'm trying to follow the matrix equation solution presented here: Convert quadratic bezier curve to parabola by @robjohn I'm assuming his solution can be used for any quadratic coordinates. My goal ...
0
votes
3answers
61 views

Inverse Matrix in Python

My understanding is that I can use Python to initialize my matrix and then apply an inverse function to find the solution.
0
votes
1answer
17 views

Correct notation for broadcasting operation

In Python numpy a row vector $u \in \mathbb{R}^n$ and its transposed $u^T$ can be added, multiplied or subtracted, yielding a $\mathbb{R}^{n\times n}$ matrix, where each element $(i,j)$ is the ...
1
vote
0answers
44 views

How to implement boundary value in Python using spectral methods

I want to solve the heat equation $$u_t=au_{xx},\quad 0\leq t, \ 0\leq x\leq\pi$$ in Python using spectral methods. I set $u(0,x)=\sin(x)$ as initial value for the time and choose $a=2$. My Code: <...
0
votes
0answers
16 views

How would I get the Heaviside function to be period in my solution?

so I am trying to solve an RC circuit problem that represents the square wave. Which I have already done on paper and now I am trying to plot it. So for this problem, we solved it using two methods, ...
0
votes
1answer
49 views

how to work out a computer program running time

I have a question and im not sure how to tackle it.... algorithms have running times proportional to the following functions of the input size, denoted N: $N^2$ $2^N$ In one minute of computing ...
3
votes
1answer
88 views

Integral of $x^2 \sin(x^2)$

I was playing around learning the SymPy syntax (python library) e then I saw an example that intrigued me. $$\int x^2\sin(x^2)dx = \frac{5x\cos(x^2)\Gamma(\frac{5}{2})}{8\Gamma({\frac{9}{4})}} + \...
1
vote
2answers
20 views

Rotate a vector to become z axis?

Say I have some vector v from the origin. I want to find the rotations required to transform v into the z-axis. My understanding is that just 1 rotation is required, but it should be around the ...
0
votes
1answer
29 views

Please help with context on this math equation for a Python application

I'm not requesting a solution... I simply do not understand what this instructor is requesting with this assignment. "Light travels at 3 * 108 meters per second. A light-year is the distance a light ...
0
votes
1answer
36 views

Derivation of the vector product

Let the vectors $\vec{w}, \vec{v} \in{\mathbb{R}^n}$ to be given. Further let $\vec{p}$ the vector projection of $\vec{w}$ on $\vec{v}$: $$ \vec{p} = \vec{w}+\vec{x} = r\vec{v} $$ The unknown $\vec{...
1
vote
0answers
44 views

Modelling congestion games in python without tons of for loop

In the bidirected triangle network as shown below, 4 agents $\{s1,s2,s3,s4\}$ have their own destination $\{t1,t2,t3,t4\}$. I am trying to model this problem with a python script without any game ...
0
votes
1answer
25 views

How to generate and visualize two 3D planes that intersect?

How would I generate two planes with 3D points that are distributed on those two planes? I would like to test two planes intersection and don't know how to generate the points of the two planes that ...
2
votes
1answer
36 views

How to obtain an homography from a single soccer image? [duplicate]

I am trying to obtain an Homography of a soccer image shot by a broadcasting camera. The original picture: I then proceed to find field lines, resulting in the following: From what I understand, at ...
-1
votes
1answer
109 views

Miller-Rabin Primality Test-Witnesses and Liars - Implementing in Python

I have been studying the Miller-Rabin Primality Test, and am interested in implementing a code in Python to count witnesses and liars. In the basic code to determine if a number is probably prime or ...
1
vote
0answers
17 views

Doubt on plotting bivariate Gaussian contours

So I'm trying to understand the implementation of a function that plots the bivariate normal contours of two variables. Thought I'd post here since the question is primarily mathematical in nature and ...
0
votes
0answers
43 views

Factorising numbers (~200 digits) methods.

are there any mathematical methods used to factorize huge integers(around 200 digits)? I'm doing that in Python, by the way. Also, if I ever get around a proper algorithm to do it, how much time ...
0
votes
0answers
51 views

Cutting 3D Point cloud and interpolate between points

I have the following data https://www.mediafire.com/file/f8tz1zbpxvyvko7/Waltersdorf_F3.csv/file Which is a 3D point cloud. I can visualize it correctly, but I want to do Cuts like the ones in the ...
0
votes
0answers
21 views

Transforming point cloud into a coordinate system

I have unknown point clouds that I need to find the rotation angle or the transformation matrix that align that point cloud into X-Z plane. picture Note that there are bears(columns) that can be used ...
0
votes
0answers
23 views

Social Force Model for Pedestrian Dynamics by Euler Method

The social force model is a model using newtonian forces to describe the movement of individuals. As seens here : page 1 Each individual feel the following forces : ->a driving force towards the ...
0
votes
0answers
84 views

Singular matrix C in LSQ subproblem - What does it mean?

I am trying to solve an Inverse Kinematics (IK) task as an optimisation problem using Python and SciPy. There exists a robot arm ...
2
votes
1answer
48 views

Average area of a rectangle inside the unit square

I recently came across this problem while toying with the problem of the average distance between 2 points in the unit square. These two points also define a rectangle, so I was wondering: What is the ...
0
votes
0answers
19 views

Unable to solve quadratic equation implemented and plotted in python

I model the inverter efficiency by eff = f(P_in) which is normed by P_in_pu = P_in/P_nomresulting in ...
0
votes
0answers
23 views

Gauss-Seidel Method, differences from key in Python

Here is the problem equation 2: x1 = 1/7(6 + y0) equation 3: y1 = 1/5(x1 + 4) Define a function, called gs1_iteration, which accepts as input values for x and y (which we think of as being xn-1 and ...
0
votes
0answers
7 views

FIltering out peaks and valleys in a noisy dataset that has drift and hills

I have a dataset from a weight sensor over 14 hours, whos resitance wheter or not something is on a table, which reads one value every second and stores it in a database. In the end the senosor is ...
2
votes
0answers
31 views

Efficient SQP with more equality constraints than parameters

My question is both a math and (computer) programming one so answers related to either are fine. Problem Setup I have the nonlinear programming problem $$ \begin{aligned} \min \;\; &f(X) \\ \...
0
votes
0answers
11 views

normalizing by using gaussian distribution for negative and positive numbers and feed in Min,Max normalization

I'm dealing in Python with a dataset which has 6 million float numbers belongs to 3 main parameters A, B , C and I map them in 24x20 matrices for each cycle and I plot them 480-values by 480-values. ...
1
vote
2answers
49 views

Generate random graphs with specific mean degree and mean edge weight

I need to generate random undirected graphs with the following characteristics: 24 nodes mean degree ranging between 1 and 23 mean edge weight ranging between 1 and 5 (weights must be integers) I ...
0
votes
0answers
35 views

How to take derivative of log loss function in gradient descent?

I know the gradient descent about $z=wx+b$. But how to implement the derivative values of $w$ and $b$ in Python? I see some example like ...
0
votes
2answers
23 views

Understanding percentile computation

I understand percentile in the context of test scores with many examples (eg. you SAT score falls in the 99th percentile), but I am not sure I understand percentile in the following context and what ...
0
votes
1answer
393 views

How to reduce matrix into row echelon form in Python

I'm working on a linear algebra homework for a data science class. I'm suppose to make this matrix into row echelon form but I'm stuck. Here's the current output I would like to get rid of -0.75, 0....
1
vote
0answers
43 views

Calculating Mahalanobis parameters from x data

Roughly speaking, the Mahalanobis distance $d(x) = \sqrt{(x - \mu)^T * \Sigma^{-1} * (x - \mu)}$ is the distance between a multivariate Gaussian distribution ($\mu$, $\Sigma$) and a point. If the ...
0
votes
1answer
64 views

Finding the appropriate polynomial fit for set of data

Is there a function or library in Python to automatically compute the best polynomial fit for a set of data points? I am not really interested in the ML use case of generalizing to a set of new data, ...
1
vote
0answers
55 views

Is there a way to avoid computing the inverse in the problem $\mathbf{y}=AB^{-1}\mathbf{x}$?

I'm writing some code in Python that has to deal with very large matrices so it is virtually impossible (atleast very sub-optimal) to compute inverses of matrices. In an earlier problem I ran into a ...
1
vote
1answer
86 views

How to code oscillator driven by Gaussian white noise? Edit: How to convert ODE to a system of SDE's?

I have written some python code which was designed to try to solve the following differential equation: $$\ddot{x}+\omega_0^2x=\eta(t),$$ where $\eta(t)$ is the gaussian white noise, with mean 0 and ...
0
votes
0answers
35 views

Question about creating a 3-rank tensor in numpy with python3

I'm trying to create a 3-rank tensor in numpy, with python3.x. I need to create this 3-rank tensor A in a very particular way. If I have 3 matrices, let's say that all of them are some $Y$ matrix (...
1
vote
1answer
51 views

Finding arrays of pixels perpendicular to a derivative

I have a question that I originally posted to Stackoverflow, but got no answers, and was encouraged to re-post here. I am developing a method for “straightening” binary-masks of pictures of carrot ...
2
votes
1answer
36 views

Calculate “areas of control” for arbitrary points

Suppose we define the "area of control" (AOC) for a single point $P_1$ as a circle of radius $r=500$ meters $C_1$. This could, for example, define the "customer base" of a small bodega in a big city. ...
0
votes
0answers
59 views

Python monte carlo value at risk with non normal distribution

What is the right way to implement a monte carlo method on a currency portfolio with non normal distribution? I am using a geometric brownian motion with normal random variables but I would like to ...
2
votes
1answer
67 views

Erdős-Straus-conjecture using polynomials in Python

I am trying to write a code in Python to do the following. We can express the Erdős-Straus-conjecture in function of some polynomials $x(k), y(k), z(k) \in \mathbb{Q}[k]$ such that $\frac4k = \frac{1}...
0
votes
1answer
25 views

How to apply this linear transformation $(x:=2x+1)$ on R-sequence result to generate points in range $[-1,1]$?

I want to used R-sequence proposed by Martin Roberts to generate points in range [-1,1]. In this post, Martin Roberts mentioned that: ... to convert to a range of [-1,1], simply apply the linear ...
0
votes
0answers
36 views

Informations about Fourier Transform for a Python project (sound manipulation)

I have a project in Python with a friend where we want to manipulate music sound, and we'll need Fourier Transforms, so I made research online and wanted to know if I understand correctly the concepts....
1
vote
1answer
111 views

Outer product reformulation of LU decomposition

For my numerical analysis class, I wanted to implement the rather simple, in-place LU decomposition algorithm. I did this the naive way and found my code was very, very slow, because I was doing every ...