Questions tagged [numerics]

Questions on the numerical functions of Mathematica, implementing numerical methods and numerical computing with Mathematica.

Filter by
Sorted by
Tagged with
-2
votes
0answers
46 views

Can I trust NMinimize

I have a function $f(x,y)$ for which Minimum[{f[ x, y], x > 0, y > 0}, {x, y}] does not find a solution. However, ...
0
votes
1answer
62 views

FindRoot - Convergence Failure

In my problem which I try to solve with FindRoot in Mathematica version 12 I usually get the following errors ...
1
vote
1answer
28 views

NSolve with Interpolation function

I am trying to apply NSolve to an Interpolation function which I have evaluated before. For a function of 1 argument everything works out but as soon as I try to apply the procedure for a function of ...
4
votes
3answers
387 views

How to set a tolerance level for equality constraints

Given two equality constraints: x+y==250 and z+p==65 where x=190, y=50, z=45, p=15, I want ...
0
votes
0answers
27 views

NIntegrate fails to converge despite using attempting to use different methods

I have the following Green's function that I am trying to evaluate for several different values on a defined mesh. The mesh and Green's function is defined below. The mesh runs from values -w/2 to w/2....
7
votes
1answer
153 views

Solving underdetermined Lyapunov equations?

I'm wondering if there's an efficient way to get a solution (ie, LeastSquaressolution) for Lyapunov equation $AX+XA=C$ with symmetric positive definite $ A $ and $ ...
1
vote
1answer
69 views

Numerical solution to Differential equation

I want to get the differential solution numerically. I used wolfram alpha. here is the link. I tried this code on the Mathematica file. ...
6
votes
2answers
771 views

Integration of Interpolated function take an unacceptable amount of time

I have a simple integration which, when using an interpolation function, is taking too long to calculate: ...
2
votes
1answer
67 views

Product from max to min [closed]

Product[f[i], {i, 1, 4}] gives us f[1] f[2] f[3] f[4] Is there any way I can take the product it will give something ...
3
votes
1answer
88 views

Solving a stiff nonlinear ODE system

The system I am trying to solve is simple, but looks pretty stiff and I have unsuccessfully tried to solve it with StiffnessSwitching. It is the following one: <...
2
votes
1answer
65 views

Evaluating the Poincaré section for Hénon-Heiles potential through Hénon Method

I must find a poincaré section of a Hénon-Heiles system as described in Hénon-Heiles 1964 paper. The Hénon-Heiles Hamiltonian is the following, $$ H = \frac{1}{2}(p_{1}^{2}+p_{2}^{2}+q_{1}^{2}+q_{2}^{...
2
votes
1answer
127 views

Is NumberForm double rounding numbers?

A number like 0.644696875 is represented internally as 0.6446968749999...: N[FromDigits[RealDigits[0.644696875, 2], 2], $MachinePrecision] (* 0.6446968749999999 *) ...
1
vote
0answers
37 views

What is used for the % symbol in mathematica? [duplicate]

Im new in mathematica i want to know logic about this program. I got this code: {{vo, vn, Ii}} = {vo, vn, Ii} /. %; i know that the syntax /. is for replacement but i dont know whats going on with ...
9
votes
1answer
278 views

Why ArcTan[1, 0. I ] yields -1.5708+0. I?

Bug introduced in 5.2 or earlier and persisting through 12.0.0 Why ArcTan[1, 0. I ] yields -1.5708+0. I ? The result should ...
16
votes
2answers
292 views

Improving Performance of an XY Monte Carlo

I normally write my Monte Carlo codes in Fortran for speed, but I was doing some quick and dirty work and wrote one in Mathematica for the XY model on a square lattice (see Kosterlitz-Thouless ...
1
vote
1answer
17 views

Numerical Maximization with Alternating Sum

I need to maximize a function that involves an alternating sum and a set of constraints. I have tried the following code: NMaximize[{(-1)^{m}*n!, n + m == 7, m > 0, n > 0}, {m, n}] However, the ...
1
vote
1answer
61 views

Inversion of a hypergeometric function

I have been trying to invert the hypergeometric function $$\rho(r)=\frac{2b}{1-q}\sqrt{1-\left(\frac br\right)^{1-q}}\,_2F_1\left(\frac{1}{2},1-\frac{1}{q-1};\frac{3}{2};1-\left(\frac br\right)^{1-q}\...
1
vote
1answer
79 views

How is the best way to integrate using loops

I'm using Mathematica, and I want to integrate a function f[wr] in wr using some method that works with a Table/Do/For in the variable wr. I tried to use something like the Riemann's sum, to evaluate ...
1
vote
2answers
83 views

How to sample numerically a function using a mesh-grid function in 3D?

I am working on a problem where I want to sample a scalar function f[x,y,z]. The problem is how to obtain a mesh-grid in 3D (A grid of points in x,y, and z). In order to study this function. Of ...
6
votes
1answer
95 views

Suppressing analytical evaluation in NDSolve

I am trying to find a numerical solution to a set of coupled ODEs with NDSolve. Let us say $\boldsymbol{X}$ is a vector, and $\boldsymbol{F}$ is a non-linear vector ...
2
votes
0answers
35 views

When mapping FindMinimum to a list, how to find out which instance does not converge

I defined a function f[x,y] and wanted to study its minimum over x when viewing y as a ...
2
votes
1answer
137 views

MMA 12: Transient plane stress problem

Based on the numerical example enter link description here which is proposed by @Hugh and @user21, then, I continue to solve transient plane stress problems (...
0
votes
3answers
54 views

Instability of FindRoot solution

Using FindRoot on a smooth function of a parameter and a variable, the resulting solution should be a smooth function of the parameter, by the Implicit Function ...
3
votes
3answers
312 views

Issue with ContourPlot

I am trying to Contour plot the solutions "$x$" of an equation versus $k$ for some fixed $T$ values. However, the contour plot is giving incorrect plot perhaps due to some accuracy issues. e.g., at ...
8
votes
0answers
94 views

How to modify NDSolve`StateData without crashing the kernel?

Probably a hard question, but it's better to cry out loud. Reminded by Chris K, I noticed my fix function has been broken since v11.3. After some checking, I ...
0
votes
1answer
177 views

Fourier Collocation For Heat Equation [closed]

In fact My problem is this $$\frac{\partial u}{\partial t}+\ sin(y)\frac{\partial u}{\partial x}=\nu(\frac{\partial^2 u}{\partial x^2} +\frac{\partial^2 u}{\partial y^2})$$ But I wanted to test the ...
5
votes
2answers
120 views

Using NDSolve on wave PDE on string, when solution given at 2 different times instead of initial velocity?

This is a PDE taken from a Maple document. Mathematica DSolve currently unable to solve it. I wanted to verify Maple solution using NDSolve. This is string of length 1, fixed on the left, and free ...
10
votes
2answers
290 views

Solving Cahn-Hilliard equation: LinearSolve: Linear equation encountered that has no solution

I have built the Cahn-Hilliard Eqs. in MMA (Mixed Formulation, second order), However, it doesnot work in MMA using Finite Element. LinearSolve: Linear equation encountered that has no solution. And ...
2
votes
1answer
58 views

NIntegrate outputs huge value compared to expected [closed]

I'm trying to replicate something that my professor has done. He's done this on the software MATHCAD but I'm more familiar with Mathematica. ...
1
vote
1answer
59 views

Random intial conditions using finite element method

How can we define the initial value for Cahn-Hilliard problem (links) using FEM in MMA? Complete test code (I am using MIXED formulation for C1 Problem): ...
1
vote
2answers
85 views

Getting error General::munfl from NonlinearModelFit [duplicate]

I am trying to fit data to a sum of Gaussians. This data is found in a file called lpeff.txt. So I write the following code: ...
0
votes
1answer
68 views

Trying to compute erfcx(x)? [duplicate]

The function erfcx(x) = exp(x^2)erfc(x) is sometimes provided in numerical packages to avoid numerical underflow for large values of ...
0
votes
1answer
56 views

Displaying the repeating decimal expansion of a rational number [duplicate]

How do I write a decimal expansion of a rational number $a/b$ with only periodic part, e.g., given $1/7=0.14285714285714285714 \ldots$, I want just $0.142857$, the periodic part of $1/7$, to be ...
1
vote
1answer
93 views

Getting a warning that a number is too small to be represented as a normalized machine number [closed]

I have the following summations: The code: ...
0
votes
0answers
70 views

How to differentiate a function constructed through FindRoot?

I am trying to maximize a function which has as a variable another function that was solved numerically using FindRoot. My code is below.I start by defining some parameters ...
2
votes
1answer
46 views

Error with NSum : it returns NSum::nsnum: Summand (or its derivative) f[n] is not numerical at point n=17

Consider the following example (I had a lot of trouble to find a minimal working example, I think it is compactified enough now). ...
2
votes
2answers
141 views

Compute unstable integral with high precision

I want to calculate $$ \int_{\mathbb{R}^n} e^{-t_1^4-t_2^4- ...-t_n^4-(1-t_1-t_2-...-t_n)^4} \text{d}t_1 \text{d}t_2 ... \text{d}t_n $$ with the highest possible n. I tried with ...
0
votes
0answers
74 views

How to tell Mathematica to do all calculations in a notebook numerically?

I would like to tell mathematica to do all calculations numerically. I have already replaced my input by adding a dot in the end, for example : nAvg=10. But the ...
1
vote
2answers
43 views

Sum up different arrays into a new array

I have a question regarding sums in arrays. So I have the following array: ...
0
votes
1answer
52 views

Calculating the distance between two points and get direction [closed]

I am programming a molecular dynamics program with periodic boundary conditions. Here, I have a problem: I have a list of coordinates like ...
10
votes
1answer
205 views

How to calculate $\displaystyle \prod_{p}\frac{p^2+1}{p^2-1}$?

When I input $$ \prod _{p=2}^{\infty } \text{If}\left[\text{PrimeQ}[p],\frac{p^2+1}{p^2-1},1\right] $$ in Mathematica 12.0, it gives out the value $1$. The result is ridiculous, for that according to ...
1
vote
1answer
91 views

Given a function $f(t,s)$, compute $\max_{t_2\in [0,1]}\min_{t_1\in [0,1]} |f(t_1,s_1)-f(t_2,s_2)|$

Given a continuous and bounded function $f(t,s)$, $t,s\in[0,1]$, I would like to compute $$\max_{t_2\in [0,1]}\min_{t_1\in [0,1]} |f(t_1,s_1)-f(t_2,s_2)|,$$ for each numeric values of $s_1$ and $s_2$....
4
votes
2answers
64 views

Numerical equation solving with FindRoot and BandpassFilter

I have problems combining filtering of a data list and FindRoot. Here is an example: ...
2
votes
1answer
118 views

Problem with NDSolve: Maximum number of steps reached

I am using NDSolve to solving a first order autonomous system of ODEs $\dot x(t) = f(x(t))$, $x\in\mathbb R^n$ numerically for a set of initial conditions $x(0)=a,b,...
2
votes
1answer
81 views

NDSolve cannot evolve Gaussian wave packet with small width

I want to solve a 1d wave equation with initial conditions: $$ u(x,0) = f(x) = e^{-(x - x0)^2/2\sigma^2} \ \ \text{and}\\ u_t(x,0) = - f_x(x) $$ The second condition is the advection equation and ...
1
vote
2answers
151 views

NMaximize not always returning solution

This question is related to a previous question and answer here: NMinimize or NMaximize for a dynamic problem but tackles a different problem. I am trying to solve a simple linear quadratic ...
6
votes
2answers
145 views

Sorting upon the first element of a nested list and show that as numerical values

I wish to sort the below list upon the first elements: ...
0
votes
0answers
22 views

SystemException[“MemoryAllocationFailure”] with long evaluation involving FindRoot

I had earlier posted my code in a previous question, but I am reposting my code here: ...
1
vote
0answers
40 views

Exponential distribution and numerical errors?

I am working on the measure of a Curie Weiss model over a lattice $$ \mu[m] = \frac{e^{\beta N (hm + m^2)}}{\sum_z e^{\beta N (hz + z^2)}}\binom{N}{\frac{(1-m)N}{2}}2^{-N} $$ where $m\in\{-1,-1+2/N,\...
0
votes
0answers
33 views

FindRoot for a transcendental function (PolyLog)

I am trying to solve an equation involving polylog using FindRoot, I am not sure how to give the initial guess as I want to solve the equation for a variety of parameters. Here is my code: ...