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
0 answers
19 views

Rice formula on time series

I have a time-series which is a mean-reverting spread with a long-run mean (equilibrium) close to zero. I am looking to use the Rice formula to get the level crossings rate, e.g. how many times the ...
user avatar
0 votes
0 answers
10 views

Recommendations to minimize unknown function with categorical variables

Goal The goal is to minimize an output variable of a computer code whose function is unknown, we will call it F. There are 25 input variables, xij, and 5 output variables, yk. xij, where i ∈ [1,5] ...
user avatar
  • 101
-4 votes
0 answers
28 views

Is anyone familiar with pandasql? [closed]

I currently try to merge two data frames by using pandasql, but I don't know how to create a new column for my data frame. I tried the code "ALTER TABLE crsp ADD monthid INT()", and it told ...
user avatar
  • 1
3 votes
1 answer
32 views

How to create synthetic data for a decaying curve in order to extrapolate it beyond some point?

In the following curve , I would like to extend the measurements beyond $x$=1 in order to have a better estimate of the green curve compared to red line. Note: I do not have the analytical form of the ...
user avatar
  • 33
1 vote
0 answers
9 views

Is there a efficient way to find only the combinations of interest from V exciting in P [closed]

Is there a efficient way to find only the combinations of interest from V exciting in P I have a list of something like this. V = [2,3,5,7,9,12] Size of V can be ...
user avatar
-3 votes
1 answer
28 views

How can I calculate the right obit period of planets with python?

...
user avatar
-1 votes
0 answers
24 views

european call with binomial model in python

I have this exercise to resolve. Calculate the prices of a European and an American call option in an N = 3 period binomial model with $ S_0 = $ 1, $ u = \frac{1}{2} = $ 2 and $ r = - \frac{1}{4} $. ...
user avatar
0 votes
0 answers
17 views

Calculate normal vectors for each element of a grid in Python

How can I quickly calculate the normal vectors of each mesh of my grid? (grid is defined by the three matrices Mx, My & <...
user avatar
0 votes
0 answers
11 views

How to Introduce LSTM systemically to autograd? [closed]

Among all the Neural Network structures that are introduced, RNN has received noticeable attention because of the state art included in its gradient computation with backpropagation. On the other hand,...
user avatar
  • 1
1 vote
1 answer
37 views

How can I calculate $d$ in this sum with a min-term that depends on $d$?

Given $n \in \mathbb{N}$, $e_i \in \mathbb{N_{0}}$, $l_i \in \mathbb{N}$, $b_i \in \{0,1,2\}$ where $1 \le i \le n, i \in \mathbb{N}$. $$ \sum_{i=1}^n{\min\left(e_i + \frac{b_i \cdot d}{4}, l_i\right)}...
user avatar
1 vote
1 answer
61 views

How to count the ways to fill a pyramid in 2d [closed]

I am trying to count the ways to fill a 2D pyramid of base $n$. We have a base already placed of $n$ squares and we try to fill the pyramid with squares (we can place a square only if the two below ...
user avatar
  • 21
0 votes
0 answers
9 views

Linearregression of two dataframes

I have two dataframes: ...
user avatar
  • 1
0 votes
1 answer
43 views

Relationship between a,b and c that make the equation system have infinite solutions

i have this matrix \begin{cases} \phantom{2}x_1+2x_2-3x_3=a\\ 2x_1+3x_2+3x_3=b\\ 5x_1+9x_2-6x_3=c\\ \end{cases} And the excercise says that i have to find the relationship between a, b, c that makes ...
user avatar
1 vote
1 answer
34 views

Optimisation: How to compute the stepsize for the Inexact Newton's Method?

I need to implement the Inexact Newton's Method in Python. (For the sake of clearity I included the code for the algorithm below.) However, I do not understand how to implement the computation of the ...
user avatar
  • 2,452
0 votes
1 answer
35 views

Create a circle perpendicular to a vector in a 3D coordinate system

I have been working on this problem for a few days already, but could not figure it out completely. Let's assume that I have two points, pointO (0,0,0) and pointA (1,1,1). Then we can calculate the ...
user avatar
  • 3
1 vote
1 answer
52 views

Solving self-consistent equations

I am attempting to use python to programmatically calculate the values in a dataset given the following equations: \begin{align} f_{ij} = \frac{g_{ij}}{\sum_{k} g_{ik}} \\\\ g_{ij} = \frac{...
user avatar
0 votes
1 answer
23 views

Create a mesh of points on an ellipsoid

I have given 4 vectors $m, a, b, c \in \mathbb{R}^3$ (the center of an ellipsoid and its 3 main axes). I am looking for an clever way to compute a mesh of points on the ellipse, which is not to ...
user avatar
0 votes
0 answers
39 views

Numerically Solving a system of coupled Integro-differential equations with different interval of integral than solving interval

I want to solve a system of coupled Integro-Differential equations in the form below: I'm trying to solve this system of IDEs by using Python's IDESolver package, which takes its inputs as: And ...
user avatar
0 votes
0 answers
18 views

the mean and standard deviation aren't the same as those of the input data i provided after sampling

have a log-normal mean and a standard deviation. after i converted them to the underlying normal distribution's parameters mu and sigma, I sampled from the log-normal distribution however when i take ...
user avatar
-1 votes
2 answers
51 views

Possible to find rotation around x, y, z axes by knowing the polar angles $\phi, \theta$?

I'm working with a 3D cartesian system $\vec{e'_x},\vec{e'_y},\vec{e'_z}$ that moves around in a global coordinate system. I know the origo position and $\vec{e'_z}$ in global coordinates. There is no ...
user avatar
1 vote
1 answer
36 views

Equation for an ellipsoid pointing towards a point

Sorry beforehand if this question is too basic! I would like to build an utility to create an ellipsoid pointing to a certain point in 3D space. The equation I am using to built it: $$ x = a \, \sin(\...
user avatar
  • 13
1 vote
0 answers
36 views

Solving PDE in Python

Does anyone know of a "nice" library for solving PDEs in Python that will compute a functional solution, u(x_1...x_n,t). What I want is to be able to pass the PDE(eq), BCs, and/or IVPs and ...
user avatar
0 votes
0 answers
15 views

Image Deblurring Resources?

I have been researching about image deblurring methods and would like to know if anyone had some good entry points to this. I am looking for references about basic image deblurring, and mainly the ...
user avatar
0 votes
0 answers
14 views

Calculating flux jacobian using Sympy

I want to obtain the analytical expression of the flux Jacobian of an advection equation in a porous media, which is useful when doing computational fluid dynamics. I thought that I could do that ...
user avatar
0 votes
0 answers
26 views

Numerically solve inseparable ODE in Python

I have an inseparable, first-order ODE of the form $$f'(t)=g(f'(t), f(t))$$ where $g$ is a rather monstrous combination of terms making it impossible to find some $h$ such that $f'(t)=h(f(t))$. I'd ...
user avatar
  • 115
1 vote
0 answers
44 views

Fastest way to solve vertex enumeration problem in python

I have a set of 73 linear non-strict inequalities that describe a convex polytope in the 36-dimensional space. All but one of the inequalities are of the form $x>=b$ or $x<=b$. In every but one ...
user avatar
  • 11
1 vote
1 answer
25 views

Problem About the Order of Convergence of Numerical Method

Sometimes when I did convergence test for my numerical solver, I can't get the exact order of convergence even I am sure that my code is correct. I would like to ask if anyone else has experienced ...
user avatar
1 vote
0 answers
16 views

Visualising Combinations of Two Arrays

I am trying to find the optimal value range for two inputs to get the highest output $\frac{A_i-1}{B_i}$. A = [1.1, 1.2, 1.3, ..., 20] B = [1.1, 1.2, 1.3, ..., 20] So, for each combination of $A_i$ ...
user avatar
  • 13
1 vote
0 answers
46 views

Spectral theory over 2D torus

I want to write a python simulation that requires the eigenfunctions and eigenvalues of the Laplace-Beltrami operator over the torus: $$ x=(R-rcos\theta)cos\phi , y=(R-rcos\theta)sin\phi , z=rsin\...
user avatar
1 vote
0 answers
41 views

Zeleny algorithm in Python / Sage

Question. Are there any recommended or, at least, known implementations of Zeleny multi-objective simplex method (MSA) in Python, especially Sage? Side-note. I have found standard simplex ...
user avatar
  • 65
0 votes
0 answers
16 views

Solving system of PDEs with Mac Cormack method

I'm currently trying to solve the following equations numerically $$ \begin{aligned} &\frac{\partial u}{\partial t}=c_{A} \frac{\partial b}{\partial z} \\ &\frac{\partial b}{\partial t}=c_{A} \...
user avatar
-1 votes
1 answer
29 views

Solving system of linear equations across network in Python [closed]

I have a network and I would like to calculate the voltage drop across the nodes (2-5). I know V1=10 and V6=0. The equations at ...
user avatar
  • 3
0 votes
0 answers
27 views

Gradient descent calculation split in 2 steps

In a machine learning course I am taking we have an assignment with a notebook (In linear models). So far I have calculated the cost and the sigmoid in a logistic regression and the next exercise ...
user avatar
0 votes
0 answers
23 views

Numerically solving Differential Equation using Störmer-Verlet

For uni I've got this assignment where I need to numerically solve the differential equation: $$\begin{equation} \begin{cases} x' = y \\ y' = -x \end{cases} \end{equation}$$ ...
user avatar
2 votes
0 answers
40 views

Why does this algorithm for the Takagi factorization fail here?

In this paper it was found that the Takagi factorization of a complex symmetric matrix $A$ can be calculated from the singular value decomposition $A=U\Lambda V^H$ by $$ A = X\Lambda X^T \tag{1}$$ ...
user avatar
2 votes
0 answers
23 views

Approximating CDF for an aggregate loss model using FFT

For a class assignment, I was asked to calculate the VaR at levels 95% and 99.9% for an aggregate loss random variable $S=\sum_{i=1}^{N}{X_i}$, where $N \sim \mathrm{NB}(r=5,\beta=\frac{1}{5})$, and $...
user avatar
1 vote
1 answer
65 views

Proximal Gradient Descent

I am trying to solve the below optimization problem using proximal gradient descent on a dataset in python: $f(\theta) = \arg\min_{\theta \in R^d}\frac{1}{m}\sum_{i=1}^m\Big [log(1+exp(x_i\theta))-...
user avatar
0 votes
0 answers
21 views

Regression, can someone help me understand this equation?

The criterion for mapping the individual test case to the four ideal functions is that the existing maximum deviation of the calculated regression does not exceed the largest deviation between ...
user avatar
0 votes
0 answers
15 views

Rotate samples of Circles around an angle $\theta$

I have the following Python-Code ...
user avatar
  • 115
2 votes
0 answers
54 views

Numerical simulation of SDE with Lévy noise in Python - Overflow issue

My goal is to simulate a SDE with alpha-stable noise in Python. This is my code: ...
user avatar
  • 21
0 votes
1 answer
34 views

Why does Discrete Fourier Transform of $\sin^2(x)$ seemingly have an extra frequency component compared to $|\sin x|$?

I'm trying to better understand Fourier Transform. In python, I took the fourier transform of $\sin^2(x)$ and $|\sin(x)|$ and plotted the absolute value of the coefficients to see which frequencies ...
user avatar
  • 1
0 votes
0 answers
35 views

Why are similar differential equations of different class?

I am trying to solve and evaluate the following system of differential equations using SymPy. $$ m = m_{base} + m_p(1 - \frac{\mu}{\mu_{max}}) + \frac{\mu}{Y_G} $$ $$ G = (1- \delta) * \mu_{max} * \...
user avatar
  • 107
0 votes
0 answers
30 views

How is Mathematica minimizing correlation exactly with linear constraints?

I made a random data matrix as data = Table[Random[], {i, 5}, {j, 5}]; In my case it was $$ \left( \begin{array}{ccccc} 0.951203 & 0.546669 & 0.86928 &...
user avatar
  • 23.4k
0 votes
1 answer
49 views

How to calculate the time an object needs to travel along a parameterized curve?

Imagine you have an object that travels along a trajectory parameterized by time in the form: $$\vec{p} = \begin{pmatrix} x_0 \\ y_0 \end{pmatrix} + \begin{pmatrix} v_x \\ v_y \end{pmatrix} t + \frac{...
user avatar
  • 165
0 votes
0 answers
9 views

Algorithm for discretizing a rectangle

A rectangle is divided into N elements and discretized only on the boundary. Any clues on how to write an algorithm for getting co-ordinates (Xs,Ys,Xe,Ye) of an element. where (Xs,Ys) are starting ...
user avatar
2 votes
1 answer
70 views

Finding the variance of a function

In an attempt to find the variance of a function continuous in the interval $S = [a,b]$. I have proposed a solution. But am afraid that I have something wrong over here. And before any further ...
user avatar
0 votes
1 answer
20 views

How to do a base change in image coordinates?

Ok so, theoretically, this should be really simple. Image you have plotted an image and a vector, and now you want to rotate the coordinate system, e.g. by 30° counter-clockwise. How do you calculate ...
user avatar
  • 165
0 votes
1 answer
42 views

how does a non linear term affect Simple harmonic motion

Hey guys i had a question on simple harmonic motion. so im dealing with a trivial SHM equation which has a non linear term alpha included to the spring force. $$\frac{d^2x}{dt^2} = -{\omega_0^2}(1 + \...
user avatar
3 votes
2 answers
117 views

An Urn Simulator

I've written code to simulate drawing without replacement from an urn containing a different numbers of orbs of different colors. It uses random sampling. However, I need to double-check that the &...
user avatar
  • 173
0 votes
0 answers
14 views

Counterintuitive Gaussian Process inference from marginal likelihood optimization?

I was trying to develop some basic understanding of how marginal likelihood optimization can capture the underlying process. The starting point is very simple, where I simulated many Gaussian ...
user avatar

1
2 3 4 5
16