instruction
stringlengths
43
28.1k
Through obtaining an alternative form for force balance equation in a fluid mechanics problem, I stopped at a point where I have to prove this identity where $A$ and $B$ are second-order matrices:$$\nabla(A.B)=(\nabla A).B + A^T .(\nabla B)$$How can it be derived using index notation? Edit I found this proof from here....
I have a huge interest in HPC, cloud computing and quantum computing since years. I'm currently a CS student with bachelor degree and I only have some basic knowledge about HPC from online articles and youtube videos on HPC. I have applied for a couple of internships and I have an interview next week in research lab. ...
I have trouble implementing the $Z^2$ error estimator (The superconvergent patch recovery and a posteriori error estimates. Part 1: the recovery technique by Zienkiewicz and Zhu). For this, I am working with Abaqus 6.14 and use a remeshing scheme to optimize the mesh density and solution quality. I have to minimize th...
I have a dataset of crop yield of a seasonal crop, under environmental conditions (rainfall, humidity, temperature etc.). Daily environmental conditions are recorded over few years with the crop yield of each season. example: Date , Temperature , Humidity , Rainfall 1/31/2019 , 28 , 64.55 , 1.2 2/1/2019 , 28.2 , 65.81 ...
I've been learning to use the numerical quadrature of the Boost library for Cpp. In the documentation, I've found an example for 1D Gauss-Kronrod Quadrature using Boost. #include <boost/math/quadrature/gauss_kronrod.hpp> #include <iostream> int main(int argc, char *argv[]) { using namespace boost::math::quadrature; ...
At any point in time I have a list of N points, points will be added and removed making the number of total points change over time. If I just use an array to store this information, I'm concerned that it will slow things down a lot because the computer will have to move things around in memory as the number of elemen...
I have a nonlinear differential equation for $u:\mathbb{R}^2\rightarrow\mathbb{R}^3$ that I can express in the form: $ \nabla (g(u)_{ij} \nabla(u)^j) = 0 $ which is similar to the "Nonlinear Poisson" example given in the Fenics tutorial except with the nonlinearity $g$ now a matrix. However I would like to add an addi...
I was wondering if there are any Theoretical & Computational Chemistry (MM, QM) codes or publications out there that are based primarily on the Julia programming language?
I'm working with a 2D Navier Stokes PDE in the unstabilized version - the equation is a linear equation of the type $\frac{∂u}{∂t} = F(u,t)$. In order to perform time discretization with FDM (finite difference method), with theta method, this equation turns into $$\frac{u^{n+1}-u^{n}}{Δt} = θF(u^{n+1},t^{n+1}) + (θ-1)...
Currently, I have this working code where I have been able to successfully calculate the integration for standard results. But in terms of precision, how could I achieve a good tolerance? import numpy as np import matplotlib.pyplot as plt def A0(a, b, fa, fb): h0 = b - a A0 = 0.5 * h0 * (fa + fb) return A0...
Original Question I have a set of non-linear equations and I need to find the root where a subset of my solution vector is constrained to be greater than or equal to 0. I have implemented the Newton-Raphson algorithm but I am finding that some of the quantities that I need to remain positive are going negative. I am fa...
Currently I am completing all exercises in books like "Introduction to Python for Science and Engineering, David Pine" and "Guid to Scientific Computing in C++, Pitt-Francis, Whitley". I am looking for a career change after spending a long time in high school education teaching physics. Re-teaching myself from the Engi...
I am trying to solve FSI problems with finite elements and using a projection scheme (I am taking as reference the review of Guermond: Guermond, J. L.; Minev, P.; Shen, Jie, An overview of projection methods for incompressible flows, Comput. Methods Appl. Mech. Eng. 195, No. 44-47, 6011-6045 (2006). ZBL1122.76072.), f...
I'm stuck at proving the coercivity of the bilinear functional in the variational formulation of the problem: \begin{array}{c} -\nabla^{2} u=f \quad \text { in } \Omega \\ u=g_{D} \text { on } \partial \Omega_{D} \quad \text { and } \quad \frac{\partial u}{\partial n}=g_{N} \text { on } \partial \Omega_{N} \end{array} ...
Lets say I have four matrices A, B, C and D, and I want to combine them together into one new matrix for computation: $$ \left( \begin{matrix} A & B\\ C & D \end{matrix}\right) $$ How can I do this in Numpy? The only thing I can think of now is to loop through each element in every matrix.
I work on electromagnetic modeling, and I use the finite volume method as a tool, so I want to develop code by the modified finite volume method (with triangular mesh), my problem studied is in a permeable environment (ferromagnetic materials). in first i try to discetize $-\mathrm{div}(\mathrm{grad}(A)=\mu_0(J + \mat...
Suppose we have a set of points $p_1,\ldots,p_n\in\mathbb R^d$ as well as a set of weights $w_1,\ldots,w_n\in\mathbb R$. Recall that the power cell associated to the pair $(p_k,w_k)$ is given by: $$\mathcal C_k:=\{x\in\mathbb R^d:\|x-p_k\|_2^2-w_k\leq\|x-p_\ell\|_2^2-w_\ell\ \forall \ell\in\{1,\ldots,n\}\}\subseteq\m...
I tested the perf tool in Ubuntu 18.04 on a simple benchmark in our compiler (parsing some file). I ran perf several times and put here the slowest: $ sudo perf stat ./parse Construct Parse Parsing: 93ms Counting: 14ms Total: 107ms Count: 450009 String size (bytes): 2250042 Allocator usage (bytes): 48400928 Perf...
Consider the following integral: $$S(q)=\int_{x=2}^q\sin^2\left(\frac{π\Gamma(x)}{2x}\right)dx$$ And consider the functions : $$R(q)=\frac{q}{\log(q)}$$ $$T(q)=\int_2^q\frac{1}{\log(x)}dx$$ I want to compare them with each other (at least numerically for a large interval of values) If graph for very large intervals (u...
I want to evaluate the following integral: $$\int_{0}^{60} \ \left(\int_{0}^{2z} 0.5\cdot t \left(\mathrm{erf}(t-a) -1 \right)J_{0}(qt)\mathrm{d}t \right)^2 \mathrm{exp}\left(-\frac{(z-a)^2}{2s^2}\right)\mathrm{d}z $$ Where a, q and s are constants. Without the square outside the first integral, this can be easily eval...
If we evaluate the first derivative of a function F(x) on a 1D grid {$x_i$} by central difference at $x=x_i$ as $$ \frac{dF}{dx} \approx \frac{F_{i+1} - F_{i-1}}{x_{i+1} -x_{i-1}} $$ then it is known that on a uniform grid it is second order accurate but on a non-uniform grid it is only first order accurate. Now, suppo...
Is it possible to apply adaptions of the conjugate gradient algorithm i.e. Fletcher-Reeves, Polak-Ribere or others to systems of nonlinear equations? How should the equation system be adjusted so one can use those algorithms? I am asking this because in all of the literature, the pseudocode says to compute the conjugat...
What is the best FD library (or collection of libraries) for C++ codes? I am looking for some data structure implementation that offers the possibility to do parallel computations on adaptively refined grids, Thank you
Given a fair coin and a number $p\in(0,1)$. How do you design a game that finishes in a finite number of tosses with a probability of $1$? And further, with the probability $p$ you win the game. I thought about random walks where the head, you add 1, tail you subtract 1. And you want to get to $n$. But that gives an ap...
Is there a way to take an existing gmsh .msh file, and convert it to second-order elements? Specifically, I'm trying to go from 8-point hexahedra (hex8) to 20-point hexahedra (hex20). Ideally, I'd like a command-line solution. I tried this: gmsh -o output.msh -format msh2 input.msh -order 2 -0 But it doesn't seem to w...
I try to solve a maximization problem using CVX. In its simplest form, I want to maximize $$f(x,y)=y*h_b\left(\frac{x}{y}\right),$$ where $h_b(\cdot)$ is the binary entropy function. In the context of CVX, it can be written as $$f(x,y)=y*\left(entr\left(\frac{x}{y}\right)+entr\left(1-\frac{x}{y}\right)\right).$$ The c...
The laplacian equation when discretized gives a system of linear equations that can then be solved. See the answer to this question: https://math.stackexchange.com/questions/3120948/discretization-matrix-for-3d-poisson-equation Why is it that when we move from 1D to 2D or 3D, we can represent the whole system in terms ...
I am trying to solve a nonlinear poisson equation of the form: $u_{xx} + f(u_y)u_{yy} = 0$. In trying to get a handle on this problem, it seems like there are two approaches. I could either discretize this directly, and end up with a nonlinear system of equations for $u_{i,j}$ or I could apply newtons method first and ...
I was looking at the scipy.minimize documentation to see if I could find a way to terminate optimization when the loss gets below some cut-off, and I couldn't see an obvious way to do it. The callback option only lets me pass it the xk, but I need to pass additional parameters to evaluate my loss. Any thoughts on a str...
I wrote a code in Fortran to solve this differential equation using RK4 method: $$ \frac{dy}{dx}=A\sqrt{\frac{B}{y}+\frac{C}{y^2}} $$ $A$, $B$, and $C$ are some known constants. The problem is that my initial values are $x=0$ and $y=0$ and because $y=0$ is the root of denominator I get a run-time error. Does anybody k...
Excel and also Excel VBA have no built-in support for arbitrary precision arithmetic. There are a few very large add-ins that can be installed to do these sorts of calculations where the operands are hundreds to thousands of digits long. For recreation I am attempting to code in VBA similar functions without creating a...
Consider the following integrals $$ I_1(x) =\int_0^\infty\mathrm dy \frac{F(x + \mathrm iy) − F(x −\mathrm iy)}{\mathrm e^{2πy}-1}, $$ And $$I_2(x) =\int_1^x F(t)dt$$ Where, $ F(z) = \sin^2[π\Gamma(z)/(2z)]$ I want to plot (with considerable accuracy) $$R(x)=I_1(x)/I_2(x)$$ Also , see if it's apparent from plot :...
I have a system of non-linear PDEs that I expect to have shocks as well as the appearance of Gibbs phenomena (spurious oscillations that form near the shock) for 2nd-order methods or higher. I have read that an approach is to use a so-called "high-resolution scheme" that includes a flux limiter function. Essentially,...
I was wondering how we can introduce $e^{ik.x}$ terms associated with circumferencially propagating waves? In this case $\hat{e}_\theta$ is the direction of wave propagation. However, I was not able to express the exponent of exponential using a dot product because of polar coordinates. How can we introduce this dot p...
I have to solve a problem using unsupervised time series forecast. I have a dataset where three columns are given, 1. Endtime: when the row was generated ( it generates a row after each 54-55 seconds) 2. Min: min value of a wave 3. Max: max value of a wave. Here I need to predict when we would observe an abrupt change...
I have a time series of data where the increment is every minute. In order to approximate AUC, I just compute the sum of the data values, since they would all be multiplied by 1 anyway per Riemann sum approximation of the integral. I'm fairly confident that this means the data can be scrambled and still produce the co...
Given a list of some length, containing random numbers. What method would need the least amount of checks to find the largest & smallest number in the list? My best guess is: (list_length)/2 amount of checks. If you compare the first & last item, then 2'nd- first & -last item, and so on, since it makes you check 2 numb...
I am implementing an adaptive 3D FMM with the "basic" $O(p^4)$ translation operators. I am looking for clarification on the multipole-to-multipole (M2M) translation operator. I will explain my understanding: In equation 6.26, the arguments $\alpha,\beta$ of the multipole are the coordinates of the child box with respec...
I am new to computer science and I was wondering whether half precision is supported by modern architecture in the same way as single or double precision is. I thought the 2008 revision of IEEE-754 standard introduced both quadruple and half precisions.
I wrote a code in MATLAB to solve a system of differential equations, but my solution doesn't seem to take into consideration the initial conditions I specified. I am not sure how to interpret this problem. In the code below, r_0 is equal to 32612336, but the output rsol starts at 0: I will be extremely grateful for ...
I've been tinkering a little in Fortran (2008) and wrote the following to solve $Rx=b$ for $R\in\mathbb{R}^{n\times n}$ upper-triangular, $x,b\in\mathbb{R}^n$. My code looks like this: function backsub_upper(R, b) result(x) ! R is a square upper triangular matrix ! b is the vector to be solved for ! x is...
I want to solve the following 1D equation to model the time evolution of saturation in a porous medium using finite elements (I'm a beginner). The permeability $K$ and the pressure $p$ depend on the saturation $s$. The initial condition in the field $\Omega = (0,l)$ is given as: $$s(t=0)=0.1, \text{ in } \Omega $$ $$ s...
Abstract I have the next equation to find a force, for my problem: $$U=-\int \vec{m}\small{(x)}\times \vec{B}(x)dV$$ $$\vec{F}=-\nabla U$$ Considering 3-dimensional space with x,y,z coordinates, and, hence, $\vec{m}$ and $\vec{B}$ describe values at a point in the 3D space. Computing via C++. Each values described as: ...
I have a regular three dimensional Cartesian Grid with numpy.linspace(a1,an,na), numpy.linspace(b1,bn,nb), numpy.linspace(c1,cn,nc) along their respective dimensions. I now want to evaluate a function at all points $(a_i,b_j,c_k)$ on this grid. The function f(list_of_points,*args) takes a list of points and returns th...
Issue description I am working on human brain tACS simulations where I have the models of the skin, skull, csf, brain and ventricles in STL format. The shape does not matter and there are no intersections. I want to run FE analysis and use SfePy but the only problem I have so far is how to define the volume regions. Us...
I am interested in whether there an available algorithms to give me insights on how to cut a volumetric mesh?
I'm having some problems trying to implement circularly polarized light in COMSOL Muliphysics. For a isotropic homogenous media, I've obtained without problems the TE and TM reflectance curves. Following the Fresnel Equation application tutorial, I've defined a periodic port for incident light with Ex=1 Ey=i Ez=0 and ...
If I have derived a finite-difference formula for a 2D problem, for example something like: $af_{i,j}+bf_{i-1,j}+cf_{i,j-1}+df_{i-1,j-1}=g_{i,j}$ where f is the unknown function on a grid and everything else is known, how do I fill the entries in the finite difference matrix $A_{i,j}^{i',j'}$ in the general case? Can I...
I have attached 2 plots for FFT spectra. One is considered good and one is bad. The good one is classified on the basis of how closely spaced the frequencies and the bad is based on how multiple frequencies are present. I am trying to determine a dimensionless objective function that could be maximized or minimized so ...
I have a PDE which looks like Helmholtz wave equation on one dimensional domain. $$\dfrac{d^2u(x)}{dx^2}+\pi^2u(x)=f(x)$$ where $-\infty <x<\infty $ Also, $f(x)= 1$ for $-0.25<x<0.25$, I call this region "inner region" $f(x)=0$ elsewhere I truncated the computational domain using absorbing boundary conditions into $-1<...
I need to solve many least squares problems with the following matrices: $$ \pmatrix{ R \\ D_i } $$ where $R$ is upper triangular and $D_i$ is diagonal. $R$ is the same for all the problems, while $D_i$ changes for each problem. Is there some way to factor $R$ to make it efficient to solve these problems? A Givens app...
In the new version of IEEE-754-2019: IEEE Standard for floating-point arithmetic, the augmented arithmetic operations were introduced. These operations can be particularly useful in certain numerical schemes. In the paper "The IEEE Standard 754: One for the History Books" (also available here), it is described, as foll...
I am trying to calculate the exponent of a 3 x 3 matrix using the formula $\sum_{i=0}^\infty\frac {A^n}{n!}$ I believe that my error may lay in the scalar division with a factorial or the member function performing the actual exponential calls. After a couple of iterations, I see my output values explode for the simple...
I would like to understand what happens in the following: I have a really simple Poisson problem, in 1D, with $u_0 = u_N = 0$. I assembled the stiffness matrix and the right-hand side, and I applied the BCs, then forced $A$ to be symmetric. I'm studying the stability of an iterative method for solving this linear syste...
I have the decimal number: $0.023$, and I want to convert in a binary number with $52$ bit of mantissa in Double Precision: if I go to convert, using this utility here, in non-normalized form, with $52$ bits I have: $0.0000010111100011010100111111011111001110110110010001$ so when I go to normalize I obtain, the inte...
I always thought that a Dirichlet BC need to be prescribed on at least one part of the domain in order for linear elasticity to be well-posed. Is this correct? But I was recently told by a colleague that this is not true and that the problem can be well-posed by specifying 2 tractions.
I have some experience with some programming languages like C/C++, Fortran, Python, etc but recently, I am getting interested in Julia. But, I am wondering if Julia could be used to create some large CFD software like OpenFOAM (written in C++): mesh utilities, solvers, parallel computing, ...etc. So my question, is Jul...
I have a simple C++ quadtree implementation. The implementation subdivides node into four children as if there is more than one point in that particular node. At the moment I want to visualize how subdivision happened for given input points. I found a similar question that stated that we can use visualization software...
I have a symmetric positive semi-definite matrix, i.e., a laplacian and wonder what may happen when I use a CG solver, that is an algorithm for positive definite matrices. What happens when the matrix is only positive semi-definite? Can I avoid problems by somehow substracting the eigenvector for the eigenvalue 0? Fo...
Let $A,B$ be $n \times n$ matrices and $C,D$ be $n \times 1$ matrices. Moreover, all entries of $A,B,C,D$ are non-negative. Assume that there is a unique matrix $X$ that solves $AX = C$. My goal is not to calculate $X$, but to determine which entry of $BX - D$ is non-negative. In solving my problem, I need to repeat th...
I am looking for the fastest way to obtain a list of the nonzero indices of a 2D array per row and per column. The following is a working piece of code: preds = [matrix[:,v].nonzero()[0] for v in range(matrix.shape[1])] descs = [matrix[v].nonzero()[0] for v in range(matrix.shape[0])] Example input: matrix = np.array([...
I have a function which takes 100+ coefficients and outputs $x$. I wish to optimise $x$. Running the simulation 50 000 times will take around 15 minutes, however, this happens in parallel - and the separate CPUs do not communicate with each other. When I try usual gradient descent methods I end up with something whic...
In this question I'm looking for a discussion on coordinate transformations. Say I have a PDEs of the form $$ \frac{\partial}{\partial t} \, V(t,x) \ = \ \Bigg\{r(x,t) - \sum_{m=1}^D \mu_m(t,x)\frac{\partial}{\partial x_m} - \frac{1}{2} \sum_{m=1}^D\sum_{n=1}^D\Gamma_{mn}(t,x) \frac{\partial^2}{\partial x_m \partial x_...
I am quite familiar with finite difference schemes in cartesian coordinates. The key point here is that every point in the cartesian grid is treated equally as the spacing between consecutive points is same. I want to know how one would perform finite-differencing in cylindrical (or even spherical) systems. I believe m...
I am trying to compare the result of numerical integration of time independent Runge_Kutta, github page for stochastic differential equations with the analytical solution. True answer match the rk1_ti_step. But I get different results for rk2_ti_step. I used the same random normal array and pass it to the integration f...
I wrote the following code to compute the approximate derivative of a function using FFT: from scipy.fftpack import fft, ifft, dct, idct, dst, idst, fftshift, fftfreq from numpy import linspace, zeros, array, pi, sin, cos, exp import matplotlib.pyplot as plt N = 100 x = linspace(0,2*pi,N) dx = x[1]-x[0] y = sin(2*x)+...
I have a matrix whose many rows are already in the upper triangular form. $$\begin{bmatrix} x_{11} & x_{12} & x_{13} & x_{14} & x_{5} \\ 0 & x_{22} & x_{23} & x_{24} & x_{25} \\ 0 & 0 & x_{23} & x_{34} & x_{35} \\ 0 & 0 & 0 & 0 & x_{45} \\ x_{51} & x_{52} & x_{53} & x_{54} & x_{55} \\ x_{61} & x_...
I am retrying this question since I didn’t do so properly last time: I have implement a simply c++ CUDA example that takes A [m x 1] and B [1 x N] and adds them element wise with what I am used to being called “implicit” array expansion (MATLAB term). I have two questions: Why do I not run into errors with two threads...
I want to simulate the propagation of a sinusoidal plane wave in a rectangular domain using Finite Elements Method. First, the wave should propagate through a fluid medium, then it will encounter a wall of solid material with some thickness, and then continue its propagation in the fluid. I am aware I have to consider ...
I have a large problem that I'm optimizing with Newton method. This involves a large sparse Hessian matrix. For better convergence and not to get stuck prematurely, I'd like to make the Hessian positive semidefinite. I leafed through some material: Nearest positive semidefinite matrix to a symmetric matrix in the spec...
In cuSPARSE, you can solve a sparse triangular linear system by calling cusparse<t>csrsv2_solve(). However, you need to call cusparse<t>csrsv2_bufferSize() and cusparse<t>csrsv2_analysis() first. From what I read in the doc, it seems: csrsv2 might need additional memory, and csrsv2_bufferSize() tells you how much ...
What would be the best way to estimate the trace of a large, distributed matrix, if one only know its action on a vector throug a parallel "matvec" routine? In the application I am interested in, the matvec routine comes from the discretization of a PDE. In most cases, I cannot modify this routine. I do not need machin...
I have a matrix B which is sparse and try to utilize a function scipy.sparse.linalg.spilu specialized for sparse matrix to factorize B. Could you please explain why this function is significantly less efficient than the function scipy.linalg.lu for general matrix? Thank you so much! import numpy as np import scipy.lina...
I wonder why OpenFOAM code has its own data structures Lists, HashTables, ... etc. when there is the STL in C++? Another question related to the linear solvers, Why it is not using other mature libraries like PETSc, Trilinos,... ? Are there any good reasons behind those choices?
In genetics and breeding, we typically have two parent genotype (may or may not be the same) which can produce a set of offspring with certain probability (assuming simple Mendelian inheritance). I am looking for a way to determine given a set of parent, what is the shortest path to a particular offspring genotype (and...
I'm implementing a genetic algorithm to optimise $x$ so as to minimise the RMSD error $r(x)$ between my model and experimental data. During the selection stage of recombination, I wish to select 'chromosomes' for breeding using fitness proportionate selection. This means that each chromosome $x$ is selected with a prob...
I have been given a binomial distribution: $$B(m+n;n,p)=\frac{(m+n)!}{m!n!}p^mq^n.$$ Here $m = 10^3$, $n=10^2$, $p=10^{-2}$, $q=1-p.$ I'm using MATLAB to compute log $B(m+n;n,p)$ and store the value in logB m=10^3; n=10^2; p=10^(-2); q=1-p; logB=log(factorial(m+n)/(factorial(m)*factorial(n))*p^m*q^n) I get logB as NaN...
I have a matrix K in Petsc. I want to delete the $n^{th}$ row and $n^{th}$ column of this matrix and restructure it. I am a beginner in Petsc. Can you suggest how to do it? Example: I have matrix K of size 100 x 100. I want to remove the 10th row and 10th column so that the remaining restructured matrix is 99 x 99.
I have a molecule LiBH2 with C2V point group. I used 3-21G basis set and obtained RHF coefficients and symmetry of orbitals. I wish to find the set of orbitals (a,b,i,j)( where a and b are occupied and i and j are virtual oritals) that contribute to MP2 correlation energy. That is, in the process I have to find the non...
I have been working on finite element code in Fortran 2008, and have implemented my own sparse matrix types. I have found that mapping local stiffness matrices (real type) to a global COO sparse type and then converting to CSC works well but above a certain size, sorting the COO becomes prohibitive. Instead I would lik...
https://www.unige.ch/~gander/Preprints/42540.pdf. here I have a problem in section $4,$ of approximating the symbol $\sigma_i(k)$. My understanding is, to get back the operator $S_i$ we have to use inverse Fourier transform, but $\sigma_i(k)$ is in square root form and that creates a problem. I think i am not totally ...
How would I use a random number generator to give random numbers from a top hat distribution in Fortran? I've seen lots of information about how to make a Gaussian random number generator, but not one with a top hat distribution.
I am numerically computing the following integral as a function of positive $k$. $$I(k) := \int_0^\infty x^b(k+x)^{a-1} e^{-x} dx \tag1$$ It is shown in math.stackexchange.com that this can be expressed as the confluent hypergeometric function of the second kind $$I(k) = k^{a+b} \Gamma(b+1)\, U(b+1, a+b+1, k) \tag2$$ ...
In terms of numerical optimization, the newton-rapson method requires a pos. definite Hessian $\nabla^2f$ respectively pos. curvature for computing the next step $p_k$ by solving $$\nabla^2 f p_k = -\nabla f$$ If I'm dealing with a vector valued function, e.g. a system of equations $F$, the newton step $p_k$ gets comp...
Artificial Intelligence (AI) and its subsets i.e. Deep Learning (DL), Machine Learning (ML) etc. are becoming more and more ubiquitous in engineering, technology and science. Modeling and Simulation (M&S) is no exception. I am currently engaging in a project with the objective of exploiting the synergy put forward by A...
I have a list of probabilities $p_k$, each corresponding to a Bernoulli distribution. These values of $p_k$ are all small (let's say 0.1% or less). I want to prepare a data structure that allows quickly sampling each of the Bernoulli distributions and returning the sparse set of them that returned 1 instead of 0. Naive...
I want to simulate the response of a nonlinear system given in the following form: $$ \dot{x_1} = f_1(\bar{x_1})+g_1(\bar{x_1})x_2, \ x_1(0) = 0.2 $$ $$ \dot{x_2} = f_2(\bar{x_2})+g_2(\bar{x_2})x_3, \ x_2(0) = 0.5 $$ $$ \dot{x_2} = f_3(\bar{x_3})+g_3(\bar{x_3})u, \ x_3(0) = 0.5 $$ $$ y = x_1 $$ where $u$ is the control...
I have a sparse symmetric positive-definite matrix $M$ and I expect the entries in some rows/columns to have very different orders of magnitude (up to a factor of $10^8$) than the entries in others. If I am going to solve a linear system involving $M$ using sparse Cholesky decomposition, is there any numerical benefit ...
I’m using Mathematica home edition software to numerically solve a specific inflation equation in cosmology. The ODE equation is forth- order, non-linear, stiff. I was using the stiffness switching method and with Working Accuracy of 60, 100, 200, but I’m not getting a stable result. Plugging in the result back into th...
I'm solving a system of linear equations obtained from the FEM discretization of a simple linear elasticity problem on a cube with zero displacements at one plane and a load on the opposite one. The system size is about 85000. I use conjugate method preconditioned with smoothed aggregation multigrid method that I provi...
I have a matrix multiplication in Matlab that goes as follows $$\hat{W} = N W N^{T},$$ where $^T$ means a transposition. $N$ is an incidence matrix with the dimensions m x n and W = diag(G), where G is a 1 x n row vector, which makes diag(G) n x n. So basically, when I have a large vector G, e.g. more than 1000 elemen...
I am trying to simulate the unsteady pollutant concentration along the reactor by solving the 2nd order PDE below with the stated BC and IC. which method is appropriate to solve convection-diffusion-reaction equation (unsteady state) using MATLAB. I solved the steady state using the function pdepe. Note: I have no kno...
In most of the Monte-Carlo-Algorithms I studied, I found, at the place where they compute the energy, always a line of code, where they divided by four. For example, this code-snippet is taken from here def Energy(Q): starting_energy=0 for i in range(len(Q)): for j in range(len(Q)): ...
For a given set of data points $$\{(x_i, y_i, z_i)\}$$ there exists some $$f_{ABC}(x,y)=Ax^2+Bxy+Cy^2$$ that minimizes $$\sum_i(f_{ABC}(x_i,y_i)-z_i)^2$$ $A$, $B$, and $C$ can be found quickly by directly solving/minimizing $$(\begin{bmatrix}x_1^2&x_1y_1&y_2^2\\x_1^2&x_2y_2&y_2^2\\x_1^2&x_3y_3&y_3^2\\\vdots&\vdots&\vdo...
My goal is to transform a matrix into upper triangular form in Python. I know the function scipy.linalg.lu will do LU decomposition and get both upper and lower triangular ones. I need to repeat this procedure several times. If there is functions from Scipy, blas, or lapack that compute only upper triangular matrix, th...
I have to solve the the problem $u_t+\Delta^2u=f(u)$, where $f(u)$ is non-linear, using domain-decomposition method. My approach is first using fixed point iteration on mixed form i.e to say $u^{k+1}_t+\Delta w^{k+1}=f(u^k)$ and $w^{k+1}=\Delta u^{k+1}$, then using usual domain decomposition procedure. Another approach...
Question Does lacking positive definiteness of the matrix of coefficients in a system of equations, make using iterative solvers impractical? Description Using the finite volume method, I have obtained a system of equations for the dependent variable (the unknown field). The problem is that I want to use iterative so...
I have a differential system like this, where $\Phi$ is a scalar valued unknown function: $$\nabla\Phi = \left(f_1(x, y), f_2(x,y)\right)^T$$ I'm trying to solve it in a FEM solver (COMSOL Multiphysics), where $\Phi$ would be my dependent variable and $f_1, f_2$ are known functions. Normally, the DE describing a depen...
Is it possible to solve a linear program with an active set method? If so what would be the similarities and differences to the simplex method?
Suppose that $R$ and $D$ are an $n \times m$ and $m \times m$ matrices. Assume that $m \ll n$ and that $D$ is positive definite. We would like to solve the system $(R^T R + D) x = R^T b$. This involves the matrix multiplication $R^T R$ which is quite costly, $O(m^2 n)$ in the worst-case. Instead, letting $z = R x - b$...