## Find the numerical value of the equation

B) Given that $$2x^2-3/x^2-4x+4 = 2 + A/x-2 + B/(x-2)^2$$

(i) Find the numerical value of A and B.

(ii) Hence, or otherwise, determine the stationary points and the nature.

(iii) Determine the point of inflexion on the graph.

## calculus and analysis – Numerical Mixed Partial Derivatives: How to Choose Scale?

For illustration purposes, consider the function
$$f(x, y) = (x – 1)^2 + (y – 1)^2 + sin(25(x+y)) .$$
The mixed partial derivatives at the origin are $$f^{(x,x)}(0,0) = f^{(y,y)}(0,0) = 2$$ and $$f^{(x,y)}(0,0) = 0$$ (the $$sin$$-term does not give any contribution).

I want to determine these derivatives numerically.

``````f((x_)?NumericQ, (y_)?NumericQ) := (x - 1)^2 + (y - 1)^2 + Sin(25*(x + y))
``````

as a numerical black box.
I would first try to solve the problem as follows:

``````N(D(f(x, y), {x}, {x}) /. x -> 0 /. y -> 0)
(* 2. *)

N(D(f(x, y), {y}, {y}) /. x -> 0 /. y -> 0)
(* 2. *)

N(D(f(x, y), {x}, {y}) /. x -> 0 /. y -> 0)
(* Derivative(1, 1)(f)(0., 0.) *)
``````

In the first two cases, it just works.
However, for the mixed derivative, it is well known that the simple approach fails and one must use nested calls to `ND` instead. (To keep it short, I will do that the simple way, not using the trick described here to reduce the number of function calls.) Let’s try it:

``````Needs("NumericalCalculus`");
ND(f(x, 0), {x, 2}, 0)
(* 54.6838 *)

ND(f(0, y), {y, 2}, 0)
(* 54.6838 *)

ND(ND(f(x, y), x, 0), y, 0)
(* -8.40318 *)
``````

Disaster!

The problem, of course, lies in the “scale” used for the differentiation.
We can explore how the results change as a function of the employed scale:

``````Table({
ND(f(x, 0), {x, 2}, 0, Scale -> 10^-s),
ND(f(0, y), {y, 2}, 0, Scale -> 10^-s),
ND(ND(f(x, y), x, 0, Scale -> 10^-s), y, 0, Scale -> 10^-s)
}, {s, 0, 6}
)

(*
{{54.6838, 54.6838, -8.40318},
{2.00013, 2.00013, 7.46312*10^-6},
{2., 2., -1.89464*10^-7},
{2.00001, 2.00001, 9.40594*10^-6},
{2.00063, 2.00063, 0.00106619},
{2.08502, 2.08502, -0.0788629},
{-5.68049, -5.68049, -20.9135}}
*)
``````

As we can see, there is only a very narrow window for `Scale` where `ND` yields great results.
Yet, using `N(D(...) /. ...)` in the first example, the results for the non-mixed derivatives were perfect.
My question is: how does Mathematica manage to choose the scale perfectly using that approach?
Is there a way to make Mathematica automatically choose the correct scale also for the mixed derivatives?

Bonus question: could someone explain why the accuracy of the results starts to get worse at a scale of $$10^{-3}$$ already? I would have expected the accuracy to increase until we get close to the machine precision.
This works, for example:

``````h = 10^-8;
(f(h, 0) + f(-h, 0) - 2*f(0, 0))/h^2
(* 2 *)
``````

## numerical integration – How to define a polygonal region in 2D to subsequently integrate over it?

Here is an example in 12.2.

``````poly = Polygon({{0, 0}, {1/2, Sqrt(3)/2}, {1, 1/Sqrt(3)}, {1, 0}});
NIntegrate(Log(x + y + 1), {x, y} (Element) poly)
``````

`0.366623`

Let us verify it by

``````Integrate(Log(x + y + 1), {x, y} (Element) poly)
``````

`-((36 - 12 Sqrt(3) + 12 Log(2) + 228 Sqrt(3) Log(2) + 138 Log(3) + 54 Sqrt(3) Log(3) + 9 Log(4) - 3 Sqrt(3) Log(4) + 48 Sqrt(3) Log(6) - 2 Log(8) - 2 Sqrt(3) Log(8) + 2 Sqrt(3) Log(9) - 48 Sqrt(3) Log(2 - 2/Sqrt(3)) + 90 Log(2 - Sqrt(3)) + 54 Sqrt(3) Log(2 - Sqrt(3)) - 90 Log(3 - Sqrt(3)) - 54 Sqrt(3) Log(3 - Sqrt(3)) - 180 Log(-1 + Sqrt(3)) - 108 Sqrt(3) Log(-1 + Sqrt(3)) + 72 Log(1 + Sqrt(3)) - 48 Sqrt(3) Log(1 + Sqrt(3)) - 36 Log(2 + Sqrt(3)) + 24 Sqrt(3) Log(2 + Sqrt(3)) - 18 Log(3 + Sqrt(3)) - 90 Sqrt(3) Log(3 + Sqrt(3)) - 48 Log(6 + Sqrt(3)) - 52 Sqrt(3) Log(6 + Sqrt(3)) - 72 Log(3 + 2 Sqrt(3)) + 48 Sqrt(3) Log(3 + 2 Sqrt(3)) + 36 Log(9 + 5 Sqrt(3)) - 24 Sqrt(3) Log(9 + 5 Sqrt(3)))/(8 Sqrt( 3) (19 + 11 Sqrt(3)) (-45 + 26 Sqrt(3))))`

``````N(%)
``````

`0.366623`

Addition. `NIntegrate` produces a different result if the vertices are taken couunter-clockwise as

``````poly1 = Polygon({{1, 1/Sqrt(3)}, {1/2, Sqrt(3)/2}, {0, 0}, {1, 0}});
NIntegrate(Log(x + y + 1), {x, y} (Element) poly1)
``````

`0.17812`

shows. `Integrate` produces the same:

``````Integrate(Log(x + y + 1), {x, y} (Element) poly1)
``````

`(-18 - 18 Sqrt(3) + 117 Log(2) + 88 Sqrt(3) Log(2) + 297 Log(3) + 141 Sqrt(3) Log(3) - 417 Log(4) - 209 Sqrt(3) Log(4) - 574 Log(8) - 287 Sqrt(3) Log(8) - 396 Log(27) - 228 Sqrt(3) Log(27) + Log(216) + Sqrt(3) Log(216) + 6 Log(1728) + 4 Sqrt(3) Log(1728) - 6 Log(46656) - 4 Sqrt(3) Log(46656) + 4 Log(452984832) + 2 Sqrt(3) Log(452984832) - 594 Log(18 - 8 Sqrt(3)) - 342 Sqrt(3) Log(18 - 8 Sqrt(3)) - 288 Log(11 - 5 Sqrt(3)) - 144 Sqrt(3) Log(11 - 5 Sqrt(3)) + 594 Log(9 - 3 Sqrt(3)) + 342 Sqrt(3) Log(9 - 3 Sqrt(3)) + 1188 Log(5 - Sqrt(3)) + 684 Sqrt(3) Log(5 - Sqrt(3)) + 288 Log(-8 (-2 + Sqrt(3))) + 144 Sqrt(3) Log(-8 (-2 + Sqrt(3))) - 591 Log(6 + Sqrt(3)) - 279 Sqrt(3) Log(6 + Sqrt(3)) + 1179 Log(7 + Sqrt(3)) + 567 Sqrt(3) Log(7 + Sqrt(3)) + 297 Log(15 + 8 Sqrt(3)) + 141 Sqrt(3) Log(15 + 8 Sqrt(3)) - 297 Log(17 + 9 Sqrt(3)) - 141 Sqrt(3) Log(17 + 9 Sqrt(3)))/(8 Sqrt( 3) (-3 + 2 Sqrt(3)) (9 + 5 Sqrt(3)))`

``````N(%)
``````

`0.17812`

## numerical value – N won’t evaluate expression numerically

Using N(expr) is not evaluating this expression numerically for me and I can’t figure out why. I originally thought it’s because I wasn’t doing NIntegrate but I’ve seen multiple examples of people using N(integral expr) to get a numerical result.

``````c1 = 1/(Integrate(e^(-0.04 x), {x, 5, 60}));
c2 = 1/(Integrate(e^(-0.16 x), {x, 5, 60}));
f1(x_) := c1*e^(-0.04 x);
f2(x_) := c2 * e^(-0.16 x);
P1 = N(f1(10)*f1(32)*f1(38)*f1(40))
P2 = N(f2(10)*f2(32)*f2(38)*f2(40))
``````

out $$frac{log ^4(e)}{left(frac{25.}{e^{0.2}}-frac{25.}{e^{2.4}}right)^4 e^{4.8}}$$
out $$frac{log ^4(e)}{left(frac{6.25}{e^{0.8}}-frac{6.25}{e^{9.6}}right)^4 e^{19.2}}$$

I’ve tried evaluating it numerically in different stages like at c1, or in the function and still no numerical result. Any help would be appreciated

## na.numerical analysis – Error in Gauss-Laguerre numerical quadrature scheme

The $$n$$-th Gauss-Laguerre quadrature scheme aims to approximate integral of exponentially decreassing function over $$(0 ; infty($$ by a finite sum, according to:
$$int _0 ^{+ infty} e^{-x} f(x) dx approx sum _{i = 1} ^n omega_i f(x_i) ,$$
where $$x_1$$, $$cdots$$, $$x_n$$ are the roots of the $$n$$-th Laguerre polynomial $$L_n$$
and the weights $$omega_1$$, $$cdots$$, $$omega_n$$ are chosen according to
$$omega_i = dfrac{1}{x_i big ( L_n'(x_i) big )^2}$$, $$1 leq i leq n$$.

$$bullet$$ Let us denotes by $$E_n(f)$$ the error of the quadrature:
$$E_n(f) = displaystyle { int _0 ^{+ infty} e^{-x} f(x) dx } – displaystyle { sum _{i = 1} ^n omega_i f(x_i) }$$.
The general estimation of the error of gaussian quadratures, specialized in Gauss-Laguerre scheme, is the following:

For all $$n in mathbb{N}$$, there exists $$xi in )0 ; infty($$ such that
$$E_n(f) = dfrac{n!^2}{(2n)!} f^{(2n)}(xi)$$.

Unfortunately, this is unusable in many case, since we know nothing on this $$xi$$. Therefore, we shall consider functions $$f$$ with derivatives satisfyng
$$||f^{2n}||_{infty, mathbb{R}^+} = mathcal{o}left ( dfrac{1}{n!^2} right )$$… This is a bit restrictive…

$$bullet$$ We also know the Uspensky theorem:

$$E_n(f) underset{n longrightarrow + infty}{longrightarrow} 0$$ for functions $$f$$ satisfying $$|f(x)| leq c dfrac{e^x}{x^{1 + rho}}$$ for large $$x >> 1$$, where some $$rho > 0$$.

(See J. V. Uspenksy, On the convergence of quadrature formulas related to an infinite interval, Trans. Amer. Math. Soc. 30 (1928), 542-559)

But, this do not gives explicit result on the convergence speed to $$0$$, nor a upper bound of $$E_n(f)$$ going to $$0$$.

$$bullet$$ So, what is the most precise result about the error term? In particular, how can we know with degree $$n$$ should we use to find a numerical approximation of $$displaystyle { int _0 ^{+ infty} e^{-x + sqrt{x}} dx}$$.

## numerical integration – Numerically Approximating Solutions to Differential Equation

I’m trying to numerically approximate solutions to a messy differential equation, given below
$$(1-alpha frac{1}{pi^{‘}(s_2)})(s_2-pi(s_2)+frac{beta}{2}pi(s_2)-frac{alphabeta}{2}s_2)+(p-alpha s_2)(-1+frac{beta}{2}-frac{alphabeta}{2pi^{‘}(s_2)})=0$$
and. I want to understand how the solution $$pi(s_2)$$ changes as we change $$alpha$$ and $$beta$$ and what forms such solutions will take. The initial condition is given by $$pi(1)=1$$, however I am open to investigating other boundary conditions that aren’t $$pi(0)=0$$. However Mathematica does not give any output and I’m not sure why. My code is given below.

`DSolve({-(p(s2)-a s2)+(s2-p(s2))(1-a/(p'(s2)))+b(p(s2)-a s2)(1-a/(p'(s2)))==0,p(1)==1},p(s2),s2) Manipulate(NSolve(-FractionBox(RowBox({RowBox({RowBox({"(", RowBox({RowBox({"-", "1"}), "+", "a"}), ")"}), " ", RowBox({"Log", "(", RowBox({RowBox({"-", "a"}), "+", FractionBox(RowBox({"p", "(", "s2", ")"}), "s2")}), ")"})}), "+", RowBox({"a", " ", RowBox({"Log", "(", RowBox({"1", "-", RowBox({"a", " ", "b"}), "+", FractionBox(RowBox({RowBox({"(", RowBox({RowBox({"-", "2"}), "+", "b"}), ")"}), " ", RowBox({"p", "(", "s2", ")"})}), "s2")}), ")"})})}), RowBox({RowBox({"-", "1"}), "+", RowBox({"2", " ", "a"})}))(Equal)FractionBox(RowBox({RowBox({"Log", "(", RowBox({"1", "-", "a"}), ")"}), "-", RowBox({"a", " ", RowBox({"Log", "(", RowBox({"1", "-", "a"}), ")"})}), "-", RowBox({"a", " ", RowBox({"Log", "(", RowBox({RowBox({"-", "1"}), "+", "b", "-", RowBox({"a", " ", "b"})}), ")"})})}), RowBox({RowBox({"-", "1"}), "+", RowBox({"2", " ", "a"})}))+Log(s2),p(s2)),{a,-1,1,.1},{s2,0,1,.1},{b,-1,1,0.1}) `

## numerical methods – Brute-force bifurcation diagram

I know there is unaccpeted answear in link on this problem. But lets make it clear, really. I believe it can serve as great reference starting point.

Suppose that I have system $$mathcal{D(dot{y},y,t,mu)}$$ given by ODE/DAE and some parameter $$mu$$. Using implicit integration scheme, a bunch of solutions for different (consistent) initial condition $$y_0(t_0)$$ at some parameter $$mu$$ value can be obtained.

Now, I know there are solutions which are stable (not oscillatory), limit cycles (harmonic oscillatory solution with period $$T$$ with possible harmonics), damped oscillatory solution, quasiperiodic solution and probably some chaotic behaviour. I am interested in bifurcation diagram.

In terms of pseudocode, how can I achieve this?

In particular, I am confused about picking points of time series. How do I choose them?

For ilustration, graph below have some fixed parameter value $$mu_1$$ and three different initial conditions were simulated. It clearly exhibits chaotic behaviour.

For same set of initial conditions but different $$mu_2$$, $$mu_2neqmu_1$$ I have these trajectories.

We can see, that depending on initial condition, only textit{phase dofference} occured, but all trajectories tends to be same.

Can you provide commented procedure for this?

## How do I solve a differential equation numerically after numerical integration over a part?

Suppose I have the following function
`yteq(z_) := NIntegrate(f //. params //. {x -> z}, {y, 1, 100})`
where `f//. params` is dependent on x and y such that it is impossible to integrate analytically.
I now need to to solve the ordinary differential equation `ODE = yt'(z) + z^(-2)*(yt(z)^2 - yteq(z)^2) == 0` numerically, but if I try
`sol = NDSolve({ODE, yt(1) == yteq(1)}, yt, {z, 1, 100})`
I get the error message, that the integrand `f //. params` has evaluated to non-numerical values for all sampling points in the region (1,100). I suppose that it has something to do with the order, Mathematica calculates the different steps involved, but I haven’t come up with a solution, yet.

## mathematical optimization – Numerical Minimization for a function of five variables

I have the function

``````f(w_,x_,y_, (Alpha)_,g_)=Sqrt(((w^2 + x^4) (1 + 2 w (Alpha)^2 + (Alpha)^4))/(
2 x^2 w) - (Alpha)^2 y)*Sqrt(((g w)^2/x^2) + (2 x^2)/w + (2 w (g (Alpha) - 1 )^2)/x^2)
``````

with the restrictions

$$w geq 1,$$

$$x>0,$$

$$y,alpha, g in mathbb{R}.$$

and I appeal to `NMinimize()` to find a numerical value for the minimum of the function `f(w_,x_,y_, (Alpha)_,g_)`, that is,

``````NMinimize({f(w, x, y, (Alpha), g), x > 0 && w >= 1}, {w,
x, {(Alpha), y, g} (Element) Reals}) // Quiet
``````

therefore mathematica shows the result

``````{2., {w -> 1.78095, x -> 1.33452, (Alpha) -> -8.73751*10^-9,
y -> 0.731324, g -> -2.98148*10^-8}}

``````

On the other hand, inquiring in the package help of the software I find that I can specify a non-default method which could give a better solution (with more accuracy), for example with DifferentialEvolution; that is,

``````NMinimize({f(w, x, y, (Alpha), g), x > 0 && w >= 1}, {w,
x, {(Alpha), y, g} (Element) Reals},
Method -> "DifferentialEvolution") // Quiet
``````

giving the result

``````{1.09831, {w -> 1.00016, x -> 0.962037, (Alpha) -> 0.276323,
y -> 11.3393, g -> -0.0477925}}
``````

Therefore, I have the question:

What is the best method (with mathematica) to obtain the most accurate value for the real minimum of the function?

P.D.
I am a novice with the use of NMinimize comand

## sharepoint online – Form returning Numerical answer on the form

#### Stack Exchange Network

Stack Exchange network consists of 176 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange