instruction
stringlengths
43
28.1k
Consider the standard weak form of the Poisson equation with coefficient $\alpha$: \begin{equation} \int_\Omega \dfrac{\partial v}{\partial x} \dfrac{ \partial \left( \alpha u \right) }{\partial x} = \int_\Omega v f \end{equation} If $\alpha$ is constant it can be dragged from inside the partial derivative and one c...
I am trying to use a shooting method to compute the shape of liquid-gas interface given by the following differential equation: $$ \frac{d^2 \theta}{ds^2} = \frac{f(\theta)}{h(h + 3\lambda)} $$ with $\frac{dh}{ds} = \sin\theta$. Here, $f(\theta) = -0.67(\sin\theta)^3/(\theta - \sin \theta \cos \theta)$, $\theta$ is an ...
This question is largely motivated by the famous paper "UNIFIED ANALYSIS OF DISCONTINUOUS GALERKIN METHODS FOR ELLIPTIC PROBLEMS" The Bassi and Rebay biliniar DG form is given in page 11 in the paper mentioned above as: \begin{equation} B_h(u_h, v) = \int_{\Omega} (\nabla u_h \cdot \nabla v + r([[u_h]])r([[v]])) \,dx -...
I'm currently working on understanding some very old code. They are trying to solve an underdetermined system and the comments say that they want the minimum norm solution. The system they solve is: $A x = b$, with $A \in \mathbb{R}^{5 \times n} (n > 5)$ Unless I'm mistaken, you can obtain a minimum norm solution via a...
I want to calculate the divergence of a rank-2 tensor field $$\nabla \cdot T$$ defined on the surface of a sphere in spherical coordinates. As an example, let the field be given as follows : import numpy as np np.random.seed(42) LAT = 100 LONG = 100 tensor_field = np.array([np.random.rand(LAT,LONG) for i in range(9)]...
Solver.py: import numpy as np import math E=3000000 A=2.0 truss = [ np.array([[0, 0], [0, 8]]), np.array([[0, 0], [8, 8]]), np.array([[0, 8], [8, 8]]) ] lengths=[] for i, t in enumerate(truss): lengths.append(math.hypot(t[0][0] - t[1][0], t[0][1] - t[1][1])) n_joints = len(truss) + 1 # assuming the ...
Consider this Stokes equations, $$ \left\{ \begin{array}{r} - \mu \Delta \vec{u} + \nabla P = \vec{f} \\ \nabla \cdot \vec{u} = 0 \end{array} \right. $$ Weak form I is: $$ \left\{ \begin{array}{r} {\color{red}{\mu <\nabla \phi, \nabla \vec{u} > - <\nabla \cdot \phi,P>}} &=& {\co...
I need some help to minimize a numerical integration. It's about a classical problem in physics (hydrogen atom). It can be solved analytically but I need to solve it numerically in Python. We have an electron's wave function $\psi(r,a)=e^{-r/a}$ and a Hamiltonian (in Ry units) $H=-\nabla^2-\frac{2}{r}$. The expected va...
I'm trying to do something that I thought would be very straightforward but somehow I'm struggling. I have a time series and I want to extrapolate it, assuming a linear trend, to forecast when will it reach a certain point. For that, I tried using NumPy to fit the polynomial $$ y = c_0 + c_1 x $$ with this code: from n...
I am currently working with convection equation $\frac{\partial C}{\partial t}+u\frac{\partial C}{\partial x}+v\frac{\partial C}{\partial y}=0$. I assume that the velocity field is incompressible i.e. $\frac{\partial u}{\partial x}+\frac{\partial v}{\partial y}=0$. However in most scenarios, I don't have the explicit e...
I have a finite element project based on deal.II and cmake/make as build system. I am aware of popular libraries such as deal.II, trilinos, petsc, mumps, superlu_dist,... to solve large sparse linear systems $Cx=d$. However, for some preprocessing tasks, I am looking for packages that allow me to solve $Cx = d$ subject...
I wrote the following function which is simulating a damped mass-spring oscillator. It is being driven by the audio sample input at 44.1 kHz sampling to create the same effect as a resonant bandpass filter. The "base" is being directly positioned by the audio input samples (input), then I calculate the spring length, a...
I'm developing molecular dynamics where my time-step is limited by stiffness of the bonds. I trying to get inspiration from game-engines, where they solve similar problem (hard bond constrains). These people think really hard how to get reasonable approximation with low computational effort on GPU, which is exactly wha...
The are good methods to deduce finite difference schemes for derivatives of functions of one variable. But how to get a good one for the mixed derivative of a function of two variables $u=u(x,y)$, namely: $$\dfrac{\partial^2 u}{\partial x\partial y}$$??? I know and I understand the formula $\dfrac{\partial^2 u}{\partia...
I'm working on a Uni project where I need to determine the length of a stainless steel pipe that is required to heat a fluid up to 1000°C. The pipe will be placed in an oven that can reach up to 1400°C. The pipe's outer diameter is 6mm, and the inner diameter is 4mm. I've developed the following heat transfer equation ...
I will shortly be teaching a second-year Python-based course on scientific computation in a mathematics department. It is just a one semester course with many things to cover, so I do not want to spend too much time on any one thing. However, I would like to get the students to read and understand a small chunk of co...
I have a large structure with many DOFs. But the application of force is very localized say over one or two nodes. If I try to run FEA on this with Guyan Reduction, I think the efficiency of reduction would be very less. The stiffness matrix can be partitioned into master and slave stiffness matrices: $K = \begin{bmat...
I have a smooth function $F: \mathbb{R}^n \to \mathbb{R}^{n-1}$ and points $x_0, y_0$ with $F(x_0) = y_0$. For theoretical reasons, I know that $y_0$ is a regular value of $F$, which means that the Jacobian at every point that maps to $y_0$ has full rank $n{-}1$. Since $y_0$ is a regular value, the preimage $F^{-1}(y_0...
I am trying to solve the Euler–Bernoulli beam numerically in structural dynamics analysis: $$\frac{\partial^2w(x,t)}{\partial t^2}= \frac {q(x,t)}{\mu(x)}-\frac {1}{\mu(x)}\frac {\partial^2}{\partial x^2}\left[E(x)I(x)\frac {\partial^2w(x,t)}{\partial x^2}\right]-\beta(x) \frac {\partial w(x,t)}{\partial t}$$ I use bac...
I am struggling with an assignment concerning Newton's method. We are to approximate 3 intersection points using intersecting circle coordinates P1, P2 and P3, using Newton's method. And I can do that for say 1 point at a time with an initial guess. But I need this in a for-loop for all 3 points. I am struggling with i...
What I did Using the finite difference method, I solved with a certain amount of error the following system of hyperbolic partial differential equations in cylindrical coordinates (the problem is axisymmetric, so the angular coordinate is not used): $$ {\partial ^2 u \over \partial r^2} + {1 \over r}{\partial u \over \...
I am trying to use quintic Hermite basis functions for FEM applications, could someone please direct me to the general formula that would help me generate quintic Hermite shape functions? In natural coordinates from -1 to 1, for instance in cubic Hermite functions it is $$\phi = 0.25 x^3 - 0.75x + 0.5\, .$$
When I do my project, I need to optimize piecewise linear objective functions (perhaps non convex) with equality constraints. The piecewise linear objective function may be not convex like this in the graph Since it is not convex, I fail to get the right result in https://or.stackexchange.com/questions/11583/ Now I am...
I have a 3-body simulation which must run millions of times. As far as I know, the GPU shines when it gets to preform simple operations on huge matrices/arrays. Currently I'm debugging and running my simulation one at a time, in which case there is basically no need for the GPU, since 3 objects really isn't a lot. I'm ...
Is there a standard way of implementing rolling friction in COMMERCIAL finite element software? There's no book about such a subject in COMMERCIAL FEM software though there are books on algorithms that are best for people writing code themselves (e.g. Wrigger's "Computational Contact Mechanics' book has a section on ro...
I am trying to optimize the following objective function according to some constraints. However, the optimization fails at the first iteration with the message that the desired error was not necessarily achieved due to precision loss. Does anyone have any advice as to why this happening so early on? Can you recommend a...
Here in the documentation of mosek (https://docs.mosek.com/latest/pythonfusion/debugging-numerical.html) we see: Never use a very large number as replacement for infinity . Instead define the variable or constraint as unbounded from below/above. Similarly, avoid artificial huge bounds if you expect they will not becom...
I'm trying to follow the wikipedia page about catastrophic cancellation but I've hit something that just doesn't make sense to me. They say that subtraction can amplify existing approximation errors (by making relative error of the difference much larger than relative error of the terms). But also they say that relativ...
I obtained a list of $\overrightarrow{r}_{end-to-end}$ from a Monte Carlo simulation of polymer movement. # r_end-X r_end-Y r_end-Z -177.236 100.309 -130.930 -184.354 88.047 -117.760 -172.577 87.168 -117.745 -197.651 103.270 -124.953 -190.053 104.223 -128.100 -187.985 102.387 -127.593 -190.839 91.210 -118.643 ...
suppose that I have a region called $\Omega $,suppose that this is a 2D or 3D region, how to generate the corresponding space-time mesh by using FEniCS? and how to extract the boundary and implement integration on boundary?
Finite Element allows one to divide a continuous medium into a mesh and compute structural properties of it. Instead of discretizing the continuous, why not start with a discrete method to begin with? Could we not see the entire structure as a space grid, whose equations are known and test the structure accordingly? I ...
Is there any reference on solving the heat equation on irregular geometries via creating a mesh and using the graph Laplacian instead of FEM techniques? (Convergence to real solution). That is to say, given a set of points $\{x_i\}\in\Omega$, with $\Omega$ a domain, what is the Laplacian matrix best approximating the L...
I would like to use gradient descent to "randomly sample" solutions to a set of homogeneous polynomial equations. Because the equations are homogeneous, setting all variables to 0 is a valid solution. I'd like to somehow "bias" the search to finding solutions with many of the variables non-zero. Is there an easy way to...
I'm currently reading the book computational fluid-structure interaction, but the book doesn't provide any code, and I can't understand the ALE method, could you please provide some codes written in python by using external libraries on ALE or space-time stabilized SUPG method? thank you
I am currently writing a code for the Bose-Hubbard model, and I am calculating the ground states and single-particle density matrix for different values of U and J. As U=0, one would see how the energy gap between the first two energy states would close, which happens. However, as I look at the eigenvector of the groun...
I have a NN for PINNs, which takes an 2D input and provides an 1D output. I need to normalise the input data(lets say between -1 to 1). I can think of two approaches where Approach 1: one approach computes the normalised data outside the gradient scope(NN) and passes the normalised input value into the NN x = np.linspa...
I am currently studying the effects of group velocity on the finite difference solution of the wave equation. Most of what I learned is from this source. I understand that high frequency components in the initial and boundary conditions can cause numerical dispersion and anisotropy in the 2D case. While the dispersion ...
I ran the FEM analysis for a simple supported beam problem using solid elements in plane strain condition, with linear kinematics and linear elastic material. I'm not happy with the solution since there is stress concentration at the point boundary condition, see the figure below. I know this is not avoidable for this ...
I have a program that implements a multivariate function, call it $f = \mathcal{Q}(Z,v)$ that I can compute given $Z,v$. The $v$ variable is related to the $f$ variable by another relation, call it $v = \mathcal{L}(f)$ (so given $f$ I have a program that can compute $v$). I would like to use this to obtain how $v$ vari...
I obtained a list of $r^2_{end-to-end}$ from a Monte Carlo simulation of polymer movement. #r-end-squared 58617.14512069625 55606.1082220041 51244.724846185505 65344.140277928964 63392.17236605068 62101.375689808614 58814.8832777033 60040.00627213609 52019.130880313125 56984.44642212785 ... ... ... ... I want to compu...
In ALE, we first set a referenced space for fluid, then we extend the boundary fluid displacement to the whole fluid region, take harmonic extension as an example, we need $$\Delta \left ( \hat{u} \right )=0,\hat{u_{f}}=\hat{u_{s}} \ on\ \hat{I}\, and \ \hat{n}\cdot \hat{u{_f}}=0 \ on\ \partial \hat{F}-\hat{I}$$, so ...
I am trying to self-learn concepts at the intersection of physics and programming. When reading up on the Ising Model, I find that the typical programming tutorial (such as this one) covers the Metropollis-Hastings algorithm; most online resources show this algorithm being used to flip one spin-state at a time until th...
I manage to implement adaptive sampling by drawing samples iteratively from an update distribution which is represented by a mixture of two distributions, such that $$ρ_{new} = a * ρ_{old} + (1 - a) * ρ_{add}$$ where $ρ_{old}$ is uniform distribution at first iteration and $ρ_{add}$ is always normal distribution. It go...
What sort of path should I follow to make a the transition from high school physics to computational science? Context 15 years teaching experience in physics and general science. Maths is currently rusty, but currently I teach college level physics to 14 year old students in China using algebraic approaches and soon to...
In my earlier question Interpolating the gradient of a cylindrically symmetric potential field expected obey the Laplace equation, especially near/across r=0 I give a simple example of a Jacobi relaxation script - the Laplace equation is solved for a cylindrically symmetric electrostatic lens system. The symmetry reduc...
If I have some dense matrix that can be decomposed into a product of sparse matrices with known(but different) sparsity patterns. Can I somehow use this information to more efficiently compute its Eigenvalues and Eigenvectors and its Moore-Penrose Pseudoinverse? By efficiently I mostly mean with lower memory cost since...
The elliptic integral of the second kind is given by $$ E(t,m) = \int_{0}^t \sqrt{1-m \sin(s)^2} \operatorname{ds} $$ and there is for instance a scipy function ellipeinc that computes it. The following formula comes up in the parametrization of constant negatively curved surfaces of rotation. $$ H(t,m) := \int_{0}^t ...
If we want to improve the accuracy of our numerical estimation of a derivative, we can use Richardson extrapolation. The method is very beneficial when using a centered difference scheme and the stencil can be derived the following way. Let $h$ be the step size. Using Taylor's expansion, we can write: $$f(x + h) = f(x)...
I'm trying to implement a simple Neural Network for Couette Flow. I'm working with a Fully Connected Neural Network. I'm finding that the convergence of the Neural Network is highly dependent on the problem parameters and the initialization of the weights. I'm minimizing the physics based residual, which which the deri...
I have a quintic Hermite basis functions [-1,1] for FEM applications, I wanted to check if it's nodal functionals are proper. Could someone explain nodal functionals in details and give an example of how to check them. By nodal functionals, I meant N_i[phi_j] = delta_ij, where phi_j are my basis functions on [-1,1]. No...
I'm new to OpenModelica. My problem is equivalent, to take an example from the physical world, to filling or emptying a tank between two limits of min and max height that I can determine (parameters). Filling or emptying is linear. I want to develop a dedicated block in OMEdit to do that, with the following specificati...
This is a repost from another community, I think the question would be better here. This bug has been haunting me for a while and would love new pair of eyes to help, not sure if this is the right place for such a question so please let me know. I am solving a nonlinear Poisson's equation numerically using a mixed Cheb...
Suppose I have a positive semidefinite matrix $M = \sum_i^N A_i^T A_i$ where each $A_i$ is a fat matrix of shape (m,n) and $m << n$, we can also assume that $A_i$ is full rank(but the stacked matrix might not be). I can compute the projection onto the kernel of $M$ by computing the individual projections onto the kerne...
How is the Petrov-Galerkin FEM different from more common FEMs? Could anyone give a layman description? What's the advantages of using the Petrov-Galerkin FEM?
Is there any mesh size restriction of spatial discretization in FEMs and FDMs (finite difference)? If a mesh is very coarse there is still perhaps nothing to stop the program from running and cause reporting errors, making me conclude that there is no such requirement on the spatial mesh size as that on the time step l...
Which of ode23, 45, 15s, 15i in matlab are dissipative or anti-dissipative for conservative ODEs? Do they STAY dissipative or anti-dissipative for ALL conservative ODEs nor not? If not, what about for a simple harmonic oscillator?
I wanna use matlab live scripts to run a loop updating an animation because this will allow to playback the animation. In the normal command window or m files one can use uicontrol to stop loops or close figures. But this doesn't seem to work for live scripts because whenever 'figure' is called, a figure will pop up, t...
I have read that the upwind scheme is flux conservative. Then by my understanding, in the absence of sinks/sources and with absorbing boundaries, the amount of the quantity leaving through the boundaries should be equal to the total initial amount of the quantity. However in practice this is not the result I'm getting ...
Non-dimensionalization is a really frustrating topic for me, and I imagine many others, because in school it was glossed over while being really important to implementing a simulation. I'm writing a CUDA C/C++ project on a single GPU in order to solve the Ideal MHD equations, but have run into a barrier where I need to...
I am solving a nonlinear dynamical system given by a nonlinear elastic problem which takes the following form: $$ \boldsymbol{M} \ddot{u} + \boldsymbol{K}_{\textrm{NL}}u = 0 ,$$ here $u \in \mathbb{R}^N$ is the displacement and $\ddot{u}$ is the second time derivative of the displacement or the acceleration, $\boldsym...
I'm looking for pointers/examples of solving system of equations $y_i=f_W(f_U(x_i))$ for $W,U$ where $f_M(x) \approx M x$ $U,W$ are updated simultaneously $i\in (0, 10^{12})$ Simplest example is learning $Tx=W_{10} W_9 \ldots W_1 x$ where $T$ is some matrix and $x$ is random normal vector. One can do it by computing ...
In my code I am able to implement zero Dirichlet boundary conditions, however, in my opinion my method does not seem to be as smooth and effective as possible. I am solving a Poisson's equation with two different boundary conditions, periodic along x and non-periodic (zero Dirichlet) along y. Therefore, my I have to be...
I am working on an interpolation problem with a domain in R^2 and values in R. Essentially, I have a rectilinear grid with target values for each point. I have fitted a function against these values, the function being a polynomial of a fixed degree on each subdomain between grid points. I would like to visualize the r...
I am solving the advection problem with high order numerical methods, using the method of lines. The boundary conditions and initial condition are selected in a way where I know that the exact solution should obey $0\le u \le 1$. $$ \frac{\partial u}{\partial t} + \nabla \cdot (u \textbf{v}) = 0.$$ One popular way to d...
I am completely stunned how numerical errors can diverge for so innocent programs. In Python 3.11.7 the program import math u = 5.0 for i in range(73): u = 6*math.cos(u) print(u) displays $-3.8591995867613633$. In Julia 1.9.2, the program u = 5.0 for i=0:72 u = 6.0*cos(u) end print(u) displays $-3.770177449898713$...
Where can one find Prof Lawrence Shampine's hpde matlab code? Is it well received? It's not commonly talked about.
The graph plots the X coordinate of the synchronized Lorenz chaotic system. I am self learning by reading research articles on how to synchronize identical chaotic systems. But as seen from the figure, synchronization does not happen. I used two Lorenz systems with slightly different initial conditions and played arou...
Lanczos algorithm can be used to find the largest/smallest eigenvalues of matrices. I am trying to find a good library in C/C++/Rust for finding the smallest singular value (or eigenvalue). I have attempted several open-source implementations of the Lanczos algorithms. I benchmarked them against the svds function in MA...
[Also posted here: https://mathoverflow.net/q/464433/] Many good algorithms are out there computing truncated SVD: https://mathoverflow.net/q/161252. I am trying to implement some codes to find the smallest singular value of a big matrix $A$. ARPACK can do that via eigenvalues of $M = A^\ast A,$ using Arnoldi methods. ...
I'm trying to obtain the graph of x(y) from the following system : Therefore I tried to solve this system using an Euler Method : def euler_method(v0, j0, phi0, dt): v_values = [v0] j_values = [j0] phi_values = [phi0] vx_values = np.multiply(v_values, np.sin(phi_values)).tolist() vy_values = np.multiply(v_values, np.c...
In the literature, I've seen the lasso problem phrased as the minimization of: $$\frac12x^tAx-x^tb+\lambda||x||_1$$ or of: $$\frac12||Ax-b||_2^2+\lambda'||x||_1=\frac12x^tA^tAx-x^tA^tb+b^tb+\lambda'||x||_1$$ If $\lambda=\lambda'=0$, then the second problem minimizes the norm of the gradient of the first, and the two pr...
I have written the following code in MATLAB. I also observe the same effect in Arnoldi iteration in ARPACK in C. N = 4000; A = rand(N); % Random entries in Uniform[0,1] tic AstarA = A.' * A + 5*eye(N); toc AstarAinv = inv(AstarA); % Inverse tic eigs(AstarA, 1, "smallestreal") % Eigenvalue with smallest real part toc ti...
I'm trying to learn how to compute accurate derivatives using the FFT. In the code at the end of this question I'm trying to compute derivatives of $$ f(x) = \exp(-10(x-1)^2) ,\, \, x \in [0,2] $$ This works out because the function is infinitely differentiable, decays smoothly towards the end of the interval and can b...
Below are two ways of writing what is seemingly (to me at least) exactly the same thing: void do_some_work(MPI_Request* send_reqs, int* send_counter) { for (int i = 0; i < someNumber; ++i) { // working version MPI_Request req = send_reqs[*send_counter]; MPI_Isend(ptr, n_elem, M_MPI_REAL, trg...
I'm trying to understand how BLAS libraries implement fast GEMM with support for transposed matrices. Say, I'm only operating on square matrixes (with dimensions n by n) and I update a submatrix of c in the following manner c[x:x+6][y:y+16] += a[x:x+6][slice_start:slice_end] * b[slice_start:slice_end][y:y+16] with the ...
To use newer accelerators like this, I need to perform matmul in 4-bit precision. How do I tell whether this operation is stable? Wondering if there well common heuristics in terms of properties of matrices $\{A_i\}$. For classification tasks, matrix multiplication is stable if $\langle y, y_{\text{4-bit}}\rangle>0$ w...
I have the raw data of $X$, $Y$, $Z$, where $X$ and $Y$ are inputs and $Z$ is the output. Plotting the surface gives the red curve: The surface seems to be a simple function involving trigonometric functions. For example, plotting the equation $\cos(X)^2 + \cos(Y)^2$ gives the blue surface and it looks similar to the r...
I am using ARPACK to find the smallest eigenvalue of a matrix. I use the shift and invert method. That is, looking for the largest eigenvalue of $$ (A-\sigma I)^{-1}. $$ However, I do not know $\sigma$ beforehand and have to adjust its value during the iteration process. Therefore, I need to do compute $(A-\sigma I)^{-...
Where can one find Prof A. Stanoyevitch's finite difference based PDE matlab code? They have a book on such a topic but can't find the accompanying code. Is it well received? It's not commonly talked about.
I wasn't sure if I should post this on stackoverflow rather than here, but because I have to construct a specific tensor I think here is more suitable. I have 2 tensors, $x \in \mathbb{R}^{M \times N \times L}$, and $d\in \mathbb{R}^{M \times L}$ my goal is to construct a new tensor defined as $(\cdot,\cdot) : \mathbb{...
I'm currently in the process of computing a differential cross-section for the scattering of a 420 MeV electron by an O-16 nucleus (with a Wood-Saxon charge distribution). The problem is that the resulting graphs don't look anything like they should. I first calculated the form factor for the wood-saxon charge distribu...
Heat and Burgers equations for example are both conservation laws $du/dt+dq/dx=0$, where $q=-u_x$ $du/dt+df/dx=0$, where $f=u^2$ The former is usually solved by common finite differences and finite elements while the latter usually by those specially designed for conservative PDEs like DG and finite volumes. Though hea...
So I am trying to model a dispersive dielectric using the Lorentz model in Julia, more specifically I am trying to obtain the frequency-dependent reflectivity of the material. I am ultimately trying to replicate the results in this paper. I have the set of update equations: along with the coefficients: I am trying to...
How should I evaluate the overall mass and moments of inertia (polar and transverse) of a finite elements model, having its mass matrix? Given that the global mass matrix is composed of symmetric mass submatrices (let's call these $m_{i,j}$, with $i,j = 1,2,3,\ldots, N$, $N$ = [number of nodes]) carrying information on...
I'm relatively new to the FSI world, and I'm dealing with some benchmark FSI problems at first; such as the example of a flap in a channel. (googling fsi benchmark flap 2D leads me to the example immediately) Currently I'm testing alternatives to mesh movement methods, i.e., not using a PDE to resolve the mesh movemen...
I am solving a system of the form $$ \begin{pmatrix} A & b^T \\ b & 0 \end{pmatrix} \begin{pmatrix} x \\ \ell \end{pmatrix} = \begin{pmatrix} c\\ 0 \end{pmatrix} $$ Where $A$ is a symmetric matrix with a one dimensional kernel. $A$ is positive definite on the orthogonal of the kernel. $b$ is a vector and $c$ is such ...
Suppose I have two tensors $A_{i_1,\ldots,i_M}$ and $B_{j_1,\ldots,j_N}$ where $M \neq N$ in general. We can define a tensor $C_{i_1,\ldots,i_M,j_1,\ldots,j_N}$ by $$ C_{i_1,\ldots,i_M,j_1,\ldots,j_N} = A_{i_1,\ldots,i_M} + B_{j_1,\ldots,j_N} $$ I thought I could use torch.einsum to construct such a tensor in pytorch b...
For my variable $U(t,x)$, I have implemented the thomas algorithm with $U_j^i$: $$ a(x)U_{j-1}^{i+1}+ b(x)U_j^{i+1} + c(x)U_{j+1}^{i+1} = d(x)U_j^{i} $$ Then $\textbf{A}$ is a tridiagonal vector with coefficients $a,b,c$ and I solve using $Au=d$. I can get this working fine. The issue is that I want to implement the bo...
I'm trying to fit a few X-Y points that look like exponential. I used the following scipy code: import numpy as np import scipy import scipy.optimize def custom_exponential(x, k, h): return np.exp(k * x) / h x_data = np.array([10, 20, 30, 40, 50, 60, 70, 80, 90, 99]) y_data = np.array([6, 25, 88, 243, 560, 1177, ...
I want to understand the time complexity of scipy.linalg.solve_triangular, which calls trtrs from LAPACK under the hood, so I wrote the following benchmarking script: from time import perf_counter import numpy as np import scipy def benchmark(p): L = np.ones((p, p)) b = np.zeros((p)) start_time = perf_c...
TLDR; I can keep matrix variables approximately orthogonal by taking a single gradient step in the direction of "effective rank" of matrix at each step of iterative solver, is there a more effective method with similar cost? I have an iterative solver that's minimizing a problem over $d\times d$ matrices of the form $...
I would appreciate it if you could help me solve the following coupled equation numerically $$ [-\frac{1}{2} \partial_r^2 + v_0(r) -E]\psi_{\ell} + v_1(r) \psi_{1-\ell}(r) = 0, $$ where $\ell = 0 , 1$ with initial conditions $$ \partial_r \psi_0(0) = 0,\\ \psi_1(0) = 0. $$ I do not know how to determine the initial sta...
I have two coupled ordinary differential equations in the steady state: The following code solves, using the Jacobi finite difference method, in 1d using Dirichlet boundary conditions for function $s$ and Neumann boundary conditions for function $n$. from pylab import imshow,gray,show, plot, xlim import time # Const...
I have set up Newtonian Gravity in my Game Engine, allowing me to simulate the gravitational attraction between celestial bodies. I have the following variables defined: btScalar whiteHoleMass = 5e+28; btScalar whiteHoleRadius = 500'000.0; btScalar sunRadius = 100'000; btScalar sunOrbitRadius = 50000; btScalar sunMass ...
I am trying to simulate the following 1-dimensional wave equation with trivial initial conditions and a inhomogeneous Dirac delta function: $u_{tt} - c^2 u_{xx} = \delta(x - x')\delta(t - t'), \ u(0, x) = u'(0, x) = 0.$ My finite difference scheme on the grid is found by the typical central difference formulas $u_{tt} ...
I am using cvxpy to maximize a function f(x) given the constraints -1 <= x <= 1. Let's call the solution x0. Now, I define a region around the optimal value f(x0) and want to find another solution x that lies within the defined region and that is maximally different from x0. The problem statement looks as follows: cons...
I have found many libraries for reducing filling when dong Cholesky factorisation on sparse matrices. However, I want to do fill-reduction for a different reason - given a $m\times n$ matrix $A,$ I want to find a permutation matrices $P,Q$ such that $B=PAQ$ satisfy the property that $B^\ast B$ is as sparse as possible....
I am trying to solve a matrix equation in the following discrete form: $$ \frac{K^{n+1}-K^n}{\Delta t} = [(K^{n+1} (V^{n})^T).^3 - K^{n+1} (V^{n})^T]V^n. $$ where $K^{n+1} \in \mathbb{R}^{m \times r}, V \in \mathbb{R}^{n \times r}$, $V^T V = I$(identity matrix) and $.^3$ are elementwise operations. I am attempting to s...
Cross-posted on Stats.SE and on MMSE. In the case of Monte Carlo simulations: Autocorrelation Time ($\tau_{\text{int}}$): A measure of how many steps are needed for the correlations in the chain to become small; it affects the variance of estimators based on the Markov chain. Relaxation Time ($\tau_{\text{relax}}$): ...
I am concerned looking for an exact Riemann solver for compressible 1D multi-component Euler equations, supplied with the ideal gases equation of state and under the assumptions: Mechanical equilibrium Thermal equilibrium For example for the form used by Gouasmi et al. 2020 [1]. In a question [2] of this forum, it is...