instruction
stringlengths
43
28.1k
If I were to have a data for a one-dimensional system evolving in time, essentially a two-dimensional array, and the array at each point in time is of the same size, how would I produce something like this: (Taken from Turing’s model for biological pattern formation and the robustness problem by Maini et al., 2012) I ...
In this command: [US,TS] = ordschur(U,T,select) what should replace the select to rearrange the eigenvalues in descending order (maximum value starts at the upper leftmost cell) as per ordschur Matlab documentation? Say, H=[-149 -50 -154; 537 180 546; -27 -9 -25]; [U,T]=schur(H); [US,TS]=ordschur(U, T, select); An e...
When a mesh partitioning takes place and every process works on a part of the mesh is any way to rename the global numbering of nodes(on each process) into a local numbering?Is there any software that can do it?
I'd like to know if SNOPT solver is available free of cost for academic research in any of the optimization software packages. I came across a few softwares that have SNOPT, but those require a commercial license.
I am a beginning graduate student in the field of continuum mechanics. It is my understanding that most problems in this field are numerically solved via finite element methods (FEM). However, I have also seen papers where people are using lattice spring models (LSM) as their chosen numerical method. I am not able to...
I have to simulate the following differential equation: $$\dot{x}=p$$ $$\dot{p}=-x-x^3-\gamma p+F\cos\omega t+ \delta F(t)$$ where $$\langle F(t)F(t')\rangle=2\gamma k_BT\delta(t-t')$$ $$\langle F(t)\rangle=0$$ $F=0.006$, $\omega=1.016$, $k_BT=0.008$, $\gamma=0.001$ I want to simulate for a long time of $T=800$ and...
Suppose we need to compare $\left \lfloor{a / b}\right \rfloor $ and $\left \lfloor{c / d}\right \rfloor $ . One way would of course be to calculate $a/b$ and $c/d$ by division. Is their a faster way?
In an arbitrarily unstructured mesh, shown in the figure below, in the context of finite volume method, I want to obtain an approximation of $\phi_f$, where $N$ and $P$ are cell centers of adjacent cells and $f$ is the face center- $N$,$P$ and $f$ are not aligned. CFD textbooks say: $$ \phi_f=g\phi_P+(1-g) \phi_N$$ whe...
Is there a difference between phenomenological modeling and mathematical modeling? When reading a few journal papers, I often see the former being used -- is it just fancier wording? If it's relevant, the papers I'm reading have both modeling and lab experimental studies, and both the simulations and lab measurements ...
I was searching around here for a while but I didn't find any discussion on this topic. We know that a problem is well-posed when There is a solution (existence), There is only one solution (uniqueness), The solution depends continuously on the data for the problem (stability). I suppose that as soon as either one of...
I am trying to solve Maxwell Stefan's equation over a membrane to get the transient mole fraction distribution over the membrane thickness 'z'. But somehow I am not able to code it using ODE45, more likely I am not able to write the system to solve using ODE45. It will be really great if someone can help me with the pr...
My professor taught us to always use the Matlab command axis equal for our simulation data plots - for all of our homework assignments. However, in studying the SIR infectious disease model, I'm studying a scaled version, so instead of using population counts I am more conveniently using fractions of populations, so th...
Are there any ODE solver packages that use coroutines and yield their results instead of functions and returning? Briefly, a subroutine in a programming language does some computations, returns a result to whoever called it, and then it's done. A coroutine does some computations, yields a result to whoever called it, a...
How can I write down two-dimensional Navier-Stokes equations for a simple rigid object immersed in a flow and freely falling due to gravity? I'm trying to view the vorticity that's induced by the fluid-solid interaction. I'm using Matlab for the simulations.
If I'm given some sort of shape and there is a displacement given but there are no external forces acting on the body, do I still need to write down the traction free boundary conditions or will there only be displacement boundary conditions?
I need to find the displacement field for this sphere shape in terms of $\delta$. So far, by applying boundary conditions, I know $u_r = u_\theta = u_\phi = 0$ at $r = a$ and $u_r = \delta, u_\theta = u_\phi = 0$ at $x = b$. I am confused on how to go from here, can anyone explain?
The element stiffness matrix in 3D FEM problems is build as follows: $$ K = \int\limits_{[-1,1]^3} B^T C B\, |J| \mathrm{d}r\, \mathrm{d}s\, \mathrm{d}t$$ The integral can be solved using e.g. Gauss quadrature method. But for me it seems to computational expensive if you perform the above equation for, e.g., 500.000 he...
What is the cost in terms of flops for the computation of $A$ to the power of $p$, where $p$ is a positive integer and $A \in \mathbb R^{n\times n}$ is a symmetric matrix?
I am implementing on Matlab a high-order finite differences scheme to approximate the first derivative of $f(x_i)$ given $x = [x(1), x(2),..., x(i),..., x(n)]$ and $f = [f(x(1)),..,f(x(n))]$ with $x$ a non-uniform grid from $x(1)$ to $x(n)$ (in fact they are Legendre-Gauss-Lobatto nodes in $[-1,1]$). Right now I use th...
If I have a symbolic matrix defined as T below, is there any way to lambdify this as function of variables, say σ..., and return a matrix in a way that does not allocate (besides the allocation for the matrix that is returned)? using SymPy, BenchmarkTools σ = [symbols("σ_$i$j") for i in 1:4, j in 1:4]; T = Array{Sym}(...
In this question I adress the stability property of a numerical scheme (a FDM described below) to the problem $$ \begin{align} u_{t} &= \alpha u_{xx}+\beta u_{xxxx}, & &x\in\mathbb{R},\;t>0, \\[3mm] u(x,0) &= \sin x, & &x\in\mathbb{R}, \\[3mm] u(x+2\pi,t)&=u(x,t), & &x\in\mathbb{R},\;t>0. \end{align} $$ where $\beta \l...
I'm a little at loss as to what my supervisor meant by the "hierarchical block decomposition" of a matrix, but the goal is to put a sparse symmetric adjacency matrix into a block diagonal structure to highlight the structure of the clusters present in the data. (The data captures whether the two proteins are adjacent i...
I start by saying that I do not have a strong background in numerical analysis, so I may miss some basic things or make trivial mistakes. Motivated by some problems in digital signal processing, I would like to solve numerically a linear ODE of order $m$ of the form: \begin{equation*} y(t)+ a_1(t) y'(t) + \dots + a_m(t...
I'm looking for a grid-based numerical method that allows simulating water over a grid-based terrain, presumably something like shallow water equations. I have a square grid of terrain elevation values, and I want a numerical method that evolves water level (values of height of water layer on the same grid) in real-tim...
In Jasak's Ph.D. thesis (2000), a notion is given about discretization of a transport equation: For good accuracy, it is necessary for the order of the discretization to be equal to or higher than the order of the equation that is being discretized. Question: Why?
I am having a dataset and trying to plot a 3-d plot between the independent and dependent variables.but, I am getting this error whenever I am trying to plot here is my code: temp1 = reshape(data(:,1),m,1); temp2 = reshape(data(:,2),m,1); temp3 = reshape(data(:,3),m,1); mesh(temp1,temp2,temp3); hold...
I am trying to distribute power across different devices, so that the sum is as equal as possible to the power setpoint. At the same time, the sum of power per phase must not exceed the power of the fuse and must also be between min and max power (depending on the device). So far I have reduce the problem to the follow...
Given $z_t=\sum_{i=1}^t \theta_iz_{t-i}+v_t $, where $t=1,...,N$ where $N=1024$. I need to write this in matrix form (a system of linear equations) as $\mathsf{A}\mathsf{z} = \mathsf{z} - \mathsf{v}$. In this case we have that $\mathsf{z}$ and $\mathsf{v}$ are column vectors with 1024 members and the $\mathsf{A}$ matri...
Which is the best approach to solve a PDE in parallel: 1.To split the mesh the mesh in N parts and every processor works on its own part or 2.To take the global linear system Ax=b and solve it in parallel
Can anyone explain how does the bdschur command of Matlab works? And how should the CONDMAX and BLKS be specified? It would be better if there is an associated example. Source: https://www.mathworks.com/help/control/ref/bdschur.html
I'm trying to understand how to solve Poisson equation with FFT. Say, if we have the simplest periodic example $$u_{xx}=-4\pi\cos(x)$$ The solution then should be $$u=4\pi\cos(x)$$ I really get the cosine, but with a different magnitude. So what I`m missing, and how to normalize solution with FFT properly? My code ...
MPI is an interface which enables us to create multiple processes to be run on a single machine or on a cluster of machines, and enables message passing or in short sorts of communication between processes. I am sure they are other lots of specifications which enables multi processing to execute one bigger task. Howeve...
Is there an area of computational science research that can be done on pencil and paper (with results written up for a journal format later on)? I'm wondering if there is abstract proof-based linear algebra or abstract algebraic objects being developed for computational science. Seems like it would be really fun if su...
Let $k_1 \neq k_2$ be positive reals, $t_0 > 0$ and consider the following Cauchy problem in $[0,+\infty)$: \begin{cases} y(t) + k(t)y''(t) = 0 \newline y(0) = 1/\sqrt{k_1} \newline y'(0) = 0, \end{cases} where \begin{equation} k(t) = \begin{cases} k_1 \hspace{1 cm} 0 \leq t \leq t_0 \newline k_2 \hspace{1 cm} t > t_0 ...
Given a system of equations: \begin{align} &f''(x) = -a \cdot \sin(f(x))\\ &f(0) = b\\ &f'(0) = c \end{align} $a, b, c, dt, N$ are arbitrary parameters. How to get a values of $f(0), f(dt), f(2dt) ... f(N)$. I am stuck with the non-linearity of the right part of the first equation. I will be very glad, if someone will ...
I'm looking to solve this boundary value question using the shooting method! $$\frac{d^2y}{dx^2}=y\cos(x)+\frac{\sin(x)}{x^2+2}$$ given the initial values: $$y'(x=-1)=-1\\y'(x=5)=0$$ I'm aware of the steps I should follow Guess unknown initial values $v_i$ Solve ODE with these values: $f (x|v_i)$ → final values Find...
I have a fortran 90 code and I want to solve a dense linear system with GMRES. I would prefer the restarted GMRES with preconditioning. Is there some library that you know of that I could use? Now I am solving the system with LU using dgetrf and dgetrs from LAPACK. I want to add also that the matrix is square, with di...
I am trying to implement an algorithm that finds (possibly) all solutions of a system of nonlinear polynomial equations $$F(X) = 0$$ I thought about using the (convex) homotopy $$H(X,T) = TF(X) + (1-T)G(X_0)$$ with $X_0$ a known solution to $G(X_0)=0$. By increasing $T$ iteratively from $0$ to $1$, the sought solution ...
This post is inspired by N. Higham post "What is Random Orthogonal matrix?". In this post, N. Higham links to the two papers: G. W. Stewart, The efficient generation of random orthogonal matrices with an application to condition estimators, SIAM J. Numer. Anal. 17(3), 403–409, 1980. T. W. Anderson, I. Olkin and L. G. ...
I have a rigid body that moves according to a set of governing ODEs, and I'd like to numerically visualize the vortices that are shed by this object. How could I proceed? I've been reading up on the Navier-Stokes equation and have a better grasp of it now, and I've watched some tutorials on implementing a 2D solver. ...
I am trying to write a python program that simulates the motion of a large number of particles by numerically integrating a second order ordinary differential equation. I first split the ODE into two coupled first order ODEs and solve using scipy.integrate.solve_ivp following a similar method to what is described in th...
I'm trying to perform convolutions as defined mathematically $f \star g (\tau)= \int_{\mathcal{R}}f(t-\tau)g(t) dt$ in a numerical simulation. Hence, my signal is a sampling of points $f(x_i)$. I need the computation to be precise, unbiased. Indeed, the simulation is there to show very refined effects, so I cannot disc...
I am refactoring an existing algorithm where where a RQ decomposition (as opposed to the more common QR) would be rather useful. Most common books on the subject (e.g. Golub and Van Loan) discuss QR extensively and provide algorithms for common implementations (e.g. Algorithm 5.2.1 for Householder or Algorithm 5.2.5 fo...
I was working on an Android app that requires some linear algebra with matrices. The matrices will be somewhat medium-sized as they are not too small or too big. I was originally using jBlas because of the benchmarks I have seen online but after visiting multiple forums, they have all said that jBlas would be nowhere n...
Currently, I am working on a remeshing routine for my simulations (Abaqus 6.14-1) using python scripts. The simulation deals with the Brinell indentation test and as the remeshing software I use Gmsh 4.5.2 (although the newest probably also works fine). The main script is given by main.py: createIndentationTest.py runJ...
I have a $100$x$100$ covariance matrix that looks like this. Some rows/cols are all-zero because those corresponding elements are not present in the sample from which covariance is calculated. I'm doing it this way: ... adjmats = [get_adjmat(graph) for graph in samples] # array of adjacency m...
The discrete exterior calculus is defined first using circumcentric dual cells, because the primal and dual edges are orthogonal and thus the dual cells are convex. This leads to a diagonal hodge star for 1-forms that is defined as $\star_1 = \frac{|\star\sigma^1|}{|\sigma^1|}$ for a primal edge $\sigma^1$ and a dual e...
I'm trying to solve the linear non-paraxial pulse propagation equation $$\partial_z\hat{E}=ik_z\hat{E}$$ for a field defined as $$E=E(r, t, z)$$ The equation given above uses $$\hat{E}=\hat{E}(k_\perp, \omega, z)$$. Therefore, I have to use a FFT twice, once, for going from $r$ to $k_\perp$, and once for going from $t$...
The "Stable Fluids" paper (*) by Jos Stam starts by acknowledging that "Our method cannot be found in the computational fluids literature, since it is custom made for computer graphics applications. The model would not be accurate enough for most engineering applications." Nonetheless, it is based on the Navier-Stokes ...
I'm looking at scattering of waves in a symmetrical potential as part of a research project. If a plane wave $e^{(ikr)}$ is incident on a spherically symmetric potential $V(r)$ the scattered wave is given by $S(r,\theta) = \frac{f(\theta)e^{(ikr)}}{ r}$ My understanding is that $f(\theta)=\frac{1}{k}\sum_{\ell=0}^{\inf...
With regards to protein-ligand interactions, we talk about two concepts, docking and scoring. I understand that docking means to find the best orientation of a ligand at the active site of a protein, and scoring is to compare several docked ligands to see which ligand best binds to the protein. To quote this paper, ...
I have arrived at an equation in the similarity transformation - $M_r$ = $T. M_{r-1}. T^t$ ,where $T$ is the rotation matrix and $M_r$ ,$M_{r-1}$ are similar matrices. My aim is to find the rotation matrix $T$ with a pivot element $(a,b)$ such that all elements $m_{ij} \in M$ will be as follows : $m_{ij} \neq 0$ , if $...
While implementing the Multipole-to-Multipole translation (M2M) with the following equation, $$\phi(P) = \sum_{j=0}^\infty \sum_{k=-j}^j \frac{M_j^k}{r^{j+1}} Y_j^k(\theta,\phi)$$ where, $$M_j^k=\sum_{n=0}^j \sum_{m=-n}^n \frac{O_{j-n}^{k-m} i^{|k|-|m|-|k-m|} A_n^m A_{j-n}^{k-m} \rho^n Y_n^{-m}(\alpha,\beta) }{A_j^k}$$...
Does anyone know of any published study that talks about the practical aspects of running Adaptive Lagrangian-Eulerian techniques for solid and/or fluid mechanics problems? I'm looking for things like benchmark results when doing a run weighted towards a more Eulerian grid than a Lagrangian grid or vice versa, mesh re...
I am working out some optical lattice band structures (example here). I have no issue with setting up the eigenvalue equation: $$ H_{jj'}c_{j'}=Ec_{j'} $$ Where $H$ is the tri-diagonal matrix that equations the different Fourier components. The Bloch wave is given by $$\psi =e^{iqx} u_n^q = e^{iqx} \sum_j a_c e^{2ikx...
Method of Moments and Finite Element Methods are two of the most used methods in computational electromagnetics to solve electromagnetic equations. As it is known, in FEM sparse matrixes are used while MoM uses the full-matrixes. My question is, why MoM uses full-matrix while a sparse matrix is obtained in FEM? Is ther...
I have two dimensional equation and I want to solve it using Finite Element Methods. $$ \nabla . (\alpha(x,y)\nabla u(x,y)) + \dfrac{\partial u(x,y)}{\partial x}+\dfrac{\partial u(x,y)}{\partial y}+u(x,y)=f(x,y)$$ $$\alpha(x,y)\dfrac{\partial u(x,y)}{\partial n}=g(x,y), for (x,y)\in \partial\Omega$$ To obtain its weak...
I am trying to solve nonlinear pendulum using 4th order Runge-Kutta method for limits between a=0.0 to b=110 seconds and simulated the results to observe the pendulum movement. But when I increase the number of steps N in RK4 method, the pendulum isn't decaying, it is oscillating forever, but for smaller value of N, I ...
I am a mechanical engineer, intermediated/advanced level in MATLAB and MATHEMATICA, and beginner in Python. I intend to get a PhD in aeroelasticity (FEM + CFD) and coding my own program. I intend to do that because I really like to code and it is a skill that I would want to have. Due to large mesh, these computationa...
May question is about possible approaches to solve the following system $$ \begin{array}{rcl} \nabla{n}&=&n\,\mathbf{E},\\ \nabla\cdot\mathbf{E}&=&1-n, \end{array} $$ in general with some boundary conditions (BC). In particular, I'm interested to solve it in the polar coordinates $$ \begin{array}{rcl} \partial_rn&=&nE_...
I am solving the heat equation discretized spatially via FEM and temporally via backward Euler. I get the system $$M \dot{u} = K u +f$$ where $u$ is a vector representing the solution at spatial locations. For piecewise linear basis functions, the mass matrix is defined as while the stiffness matrix $K$ is By discre...
The section 4.2 "Poor Conditioning" in the book Deep Learning defines the condition number of the function $f(x) = A^{-1}x$ as \begin{align} \underset{i,j}{\max}~ \Bigg| \frac{\lambda_i}{ \lambda_j} \Bigg|. \end{align} which is the ratio of the magnitude of the largest and smallest eigenvalue. and says When thi...
I am not sure if this is on-topic here, but I am trying. Let $x,y$ be positive real numbers. I am trying to find $$ \min_{\sqrt{a}+\sqrt{b}=\sqrt{2}}(x-a)^2+(y-b)^2$$ I tried using Mathematica for this, by running Minimize[{(x - a)^2 + (y - b)^2, Sqrt[a] + Sqrt[b] == Sqrt[2]}, {a, b}] but the computation didn't te...
I'm struggling to understand a line of FORTRAN code and was hoping someone on here would be able to help me out. These lines of code are meant to generate a flat distribution - I understand that GRNDM(RDUMMY,1) is using FORTRAN's random number generator creating a vector called RDUMMY with an array with length of 1, so...
My code is based on the similarity transformation X=VZ.I simulate the model for transformed equations involving Z by replacing the state space modelAX+BU and RX+SU with transformed equations where X is replaced with VZ and WZ resp then I apply transformation again to obtain X back. I want to execute the following Euler...
I'm working out the Galerkin method for the heat equation $$\frac{\partial u}{\partial t} - \frac{\partial^2 u}{\partial x^2} = 0$$ subject to $u(0,t)=0,u_x(1,t)=v(t)$. I want to use a Fourier basis to represent the solution, i.e. $u(x,t) = \sum_{j=1}^n c_j(t) \phi_j(x)$ where $\phi_j(x) = \sin j\pi x$. If I try to for...
I am trying to minimize a 2d function using scipy.optimize. Specifically I want to plot the minimum value of the function fun as a function of the parameter wjk. The problem is that I cannot pass wjk as a function argument as I am not optimizing over it. How to obtain the optimized value as a function of a parameter in...
In some areas of physics, for example radiation transport in plasmas, it is beneficial to re-express the convection equation in terms of a Legendre polynomial expansion. This results in a set of coupled equations for the expansion coefficients. So, if the standard convection equation for a function f is: $\partial f/\p...
My question relates to using spherical Bessel functions in Python. If my ODE contains a spherical Bessel function of the form $$j_\ell(tx)$$ and similarly $$y_\ell(tx)$$ for given values of $t$ and $x$. I used the following: from scipy.special import spherical_jn(n, z, derivative) from scipy.special import spherical_yn...
When one gives a computational methods talk, what's the right way to pronounce "Eulerian"? Is it like oiler-ree-in, 5 syllables, or oh-lure-ree-in, 4 syllables? Langrangian is simple: Langrange-Ian I live in the United States, will attend an American PhD program, and English is my first language. For Guassian, I h...
I know for large amounts of data there are online computation services or supercomputers or Beowulf cluster. For a small quantity of data, a good computer is enough. But sometimes, for medium qty of data it would be very nice to be able to use resources from the computers of my colleagues in displacement for example, o...
I'm looking to code the following function: $$|g(\theta)=\frac{1}{2k}\sum_{\ell=0}^{\infty} (2\ell +1)\sin(2\delta_{\ell})P_{\ell}\cos(\theta)|^2$$ import numpy as np import scipy.special as sp def Legendre(n,x): x=np.array(x) if (n==0):` return x*0+1.0 elif (n==1): return x else: return ((2.0*n-1.0)*...
I am trying to compute the continuant of a list of numbers $a_0, a_1,...,a_n$, defined by the recursion relation: $K_{n+1} = a_{n+1} K_n + K_{n-1}$ and $K_0 = 1$ (see Wikipedia). I am trying to use divide-and-conquer as suggested by Knuth, 1971, Page 271-272. However, my implementation: mpz_class continuant(size_t s, s...
I have a partial differential equatons as shown below. $$\dfrac{d}{dx}((1+x)\dfrac{du(x)}{dx})=0$$ With the following boundary conditions. $$u(0)=0, u(3)=10$$ To solve it using FEM, I multiplied the PDE with residual function then converted it to its weak form. Then constructed to global matrices using three elements ...
I am trying to solve the ODE for a harmonic oscillator using Scipy's odeint solver for different dampening factors. I'm using the following code, based off of this example: from scipy.integrate import odeint m = 1 # kg k = 10 # N/m omega = np.sqrt(k / m) def eps(c): return (c / (2 * mass * np.sqrt(kspring/mass)...
I want to use Simpson's rule to evaluate the following double integral: $$\int_{a}^{b}\left|\int_{0}^{z}x\cdot \mathrm{erf}(x-10)\cdot J_{0}(x) \mathrm{dx}\right|^{2}\exp(-0.5*(z-40)^2)\mathrm{dz} $$ Usually, if both the limits were numeric I would get away with just applying simps from scipy.integrate twice, but here ...
Suppose I have these two $N\times N$ lower triangular banded matrices: $A = \begin{bmatrix} a_0 & & \\ a_1 & a_0 & \\ a_2 & a_1 & a_0 \\ a_3 & a_2 & a_1 & a_0 \\ & \ddots & \ddots & \ddots & \ddots \\ & & a_3 & a_2 & a_1 & a_0 \end{bmatrix}$ $B = \begin{bmatrix} 1 & & \\ b_1 & 1 & \\ b_2 & b_1 & 1 \\ b_3 & b_2 & b_1 ...
I just came upon this paper, which details the implementation of a fast method to get eigenvalues of tridiagonal symmetric matrices : Coakley, Ed S.; Rokhlin, Vladimir, A fast divide-and-conquer algorithm for computing the spectra of real symmetric tridiagonal matrices This method relies on a divide and conquer algori...
I've been reading multiple papers and related posts for a while now, but I can't seem to find a specific answer to the issues I'm having so I hope someone can clarify things here. I'll provide some background first before diving into the issues at hand. Background Basically, I'm developing a 1D finite element code whic...
I am trying to generate random chi-squared numbers in C++, according to some degree of freedom (which can be a float). Several libraries can be used for that purpose, among which the C++11 Standard Library with the header <random>, or two Boost libraries, boost::mathor boost::random. These libraries don't exactly have ...
I'm modeling an electron that orbits the nucleus. Of course, charged particles radiate away there energy so it'll crash into the nucleus. My approach has been to to evaluate the coulomb force and add the reaction force (given by the Abraham-Lorentz formula). The equation of motion would be $F = ma = \frac{1}{r^2} - \be...
Define variables $p_i,u_i\in\{0,1\}^G$, for $i=1,\ldots,8$ and $G=30000$. Let $v$ be a constant vector also in $\{0,1\}^G$, with approximately 25% of its entries equal to $1$ (randomly located). Let $c$ be the vector $c=[1,2,3,\ldots,G]$. Let $A$ be the matrix with $1$'s along its diagonal and $-1$'s along its subdiago...
So far, I've worked a bit in modeling, simulations and simple lab experiments, and I've really enjoyed all three research methods to approach a single research question. I can write tricky (in terms of implementation), bug-free code to simulate the models that my advisor and I tinker with and modify, based on theory, ...
I need to populate a matrix $A_{kl}$, where $$ k = (m-1)J+n$$ $$ l = (p-1)J+q$$ And $$m,p = 1, 2, ..., I$$ $$n,q = 1, 2, ..., J$$ Its components are (mnpq). For populate it, I'm using a expensive 4 Do loop Do[ Do[ Do[ Do[ Print[m, n, p, q]; k = (m - 1) nC + n; l = (p - 1) nC + q; If[k <= l, A[[k, ...
I have to solve a non-linear ODE of the shape $$\partial_zA=f(A)$$ with $f$ a non-linear function and $A$ a matrix/vector with >1e6 variables (i.e. $A$ is a matrix with >1000x1000 entries). For each calculation of the right hand side of the system (i.e. $f(A)$) I have to calculate roughly five matrix-matrix multiplica...
I put together a FEM solver to do some structural analysis. At the moment I am trying to add stress visualization feature to my code. The post-processing is done with Paraview and the results with which I am trying to verify my code are from the following problem: The structure is two square plates welded on one edge t...
I have a function in python that is quite computationally expensive to evaluate, of the form: def f(x, args): ... return y_1, y_2 # where y_1 is scalar, and y_2 can # be a vector of other results I need to minimize y_1 with respect to x, and I have a quite good initial guess for x, such t...
I want to write a code in Fortran to solve this integral numerically: $$\int_{1095}^\infty \frac{dx}{x\sqrt{(x+644.153)(4.17 \cdot 10^{-5} x+0.145)}}$$ What is the best method for it? I tried Monte-Carlo and RK4 but I had to put a big number instead of infinity. To avoid infinity, I changed the variable $x$ to $1/t$. T...
I am working on static FE mesh partitioning and in order to achieve a good quality partitioning I want to know how to drecrease interprocessor communication by increasing the connectivity of elements in a subdomain.For a 2D mesh we have edge connectivity and vertex conectivity.As the names suggest 2 regions are edge-co...
I am trying to use the "shooting method" for solving Schrodinger's equation for a reasonably arbitrary potential in 1D. But the eigenvalues so evaluated in the case of potentials that do not have hard boundaries are not much accurate compared to analytical results. I thought that the problem could be solved, by making ...
This question concerns the 1-dimensional (i.e. only one spatial dimension) shallow water equations (SWE) shown below and how to find initial conditions such that we obtain a travelling pulse/wave instead of the typical water droplet scenario that yields two travelling waves in opposite directions (this corresponds to s...
The following code solves a differential equation with scipy: import numpy as np from scipy.integrate import solve_ivp t0 = 0 Z0 = np.array([0, 0, 0, 0]) sw = 0 t_final = .001 t, z = t0, Z0 if sw == 0: sol = solve_ivp(f0, [t,t_final], z, method='BDF', events=g0) Z = sol.y.T t, z = sol.t[-1], Z[-1] else: ...
The following relates to the linked question: Scattering of waves in a symmetrical potential (using python) I have attempted to solve the problem for $U(r)$ using odeint. From this, I need to find $\mathrm{arctan}(U(r))$ and continue the integration to a large $r$ I am aware that for $\mathrm{arctan}$ I should use np.a...
We have that: $\epsilon$ is the smallest positive machine number that summed to $1$ resuts in $(\epsilon + 1)$: i.e. the smallest number greater than $1$: if $p$ is precision and $\beta$ the base: $$\begin{array}{lcl} 1 & = & 0.1\underbrace{00 \ldots 00}_{p-1 \text{ zeros}} \times \beta^1 \\ 1 + \epsilon & = & 0.1\unde...
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 algorithm, and I am getting slighty different, and less optimal results. 2 nodes are being placed in the wrong group, which ...
I am looking for a way to fit a spline of order 2 to a 2d image or point cloud. The input will be an gray scale image. The start and end points are given as 2D coordinates. The goal is to find a spline that minimizes the energy or average image value that the spline is crossing. It might be easier to understand with t...
I am a master student in Mathematics, and I have to prepare a seminar for a course in mathematical methods for applied sciences. I have a good background in numerical analysis for ODEs, PDEs and hence I also would like to run some simulations in Python. I also have some experience with standard numerical methods for SD...
I have rephrased my original question to be clearer: From my understanding, a multipole expansion is used to approximate the potential from a cluster of points, and can be evaluated at any point sufficiently far away. Suppose you have a cluster of points in box A which is centered at some point in space Q. The potentia...
I'm trying to extract data from a potential field. I have an example code of a potential field, using meshgrid in MATLAB. I've pasted the code below. What I'd like to do next is 'convert' this field into a 2D graph, collect/graph the isocontours, and place data-points along the contour lines, ie. I want to collect a l...
I am trying to simulate the Cahn-Hilliard equation using Python, but the 2 fluids aren't separating into big blobs, as desired, under any conditions. I'm setting up (what I think is) an orthogonal mesh with uniform concentration values of 0.5 plus random noise values within ±0.05. $\gamma = 0.5$. $D$ = 50. Time steps o...