1
$\begingroup$

I have an messy expression and want to apply NMinimize to it, have no idea how to force NMinimize to ignore the singularities it complains about.

The code:

diff=973829./(Sqrt[1-E^(-NN^x2 x1)] NN)^(1/3)-2.35655*10^6 Sqrt[(1+(4.4289 (1-E^(-NN^x2 x1)) (-1+Log[(1+Sqrt[1-1. (1-E^(-NN^x2 x1))])/(1-Sqrt[1-1. (1-E^(-NN^x2 x1))])]/(2 Sqrt[1-1. (1-E^(-NN^x2 x1))])))/(1-1. (1-E^(-NN^x2 x1))))/NN]; objective = Sum[N[diff]^2, {NN, 1, 20}]; ParamNSQ=NMinimize[{objective,x1>0,x1<20,x2>0,x2<10},{x1,x2}]; 

It works for the restrictions {x1>0,x1<2,x2>0,x2<1}, but for {x1>0,x1<20,x2>0,x2<10} it returns errors.

$\endgroup$

2 Answers 2

1
$\begingroup$

If we take objective from @user64494 answer, we first check the region where objective \[Element] Reals

cond = FunctionDomain[objective, {x1, x2}]; pic=RegionPlot[cond, {x1, 0, 10}, {x2, 0, 10}, PlotPoints -> 100, FrameLabel -> {x1, x2}] 

enter image description here

Only your first region {x1>0,x1<2,x2>0,x2<1} nearly fits into this domain.

reg1 = Region[Style[ RegionBoundary[ ImplicitRegion[x1 > 0 && x1 < 2 && x2 > 0 && x2 < 1, {x1, x2}] ], Darker[Green]]]; reg2 = Region[Style[ RegionBoundary[ ImplicitRegion[ x1 > 0 && x1 < 20 && x2 > 0 && x2 < 10, {x1, x2}] ], Red]]; Show[{pic, reg1, reg2}] 

enter image description here

Perhaps you know how to restrict your second domain problem adapted?

$\endgroup$
0
$\begingroup$

The following works without any errors and warnings in 14.0 on Windows 10. We use exact numbers to avoid problems with the evaluation.

diff = Rationalize[973829./(Sqrt[1 - E^(-NN^x2 x1)] NN)^(1/3) - 2.35655*10^6 Sqrt[(1 + (4.4289 (1 - E^(-NN^x2 x1)) (-1 + Log[(1 + Sqrt[1 - 1. (1 - E^(-NN^x2 x1))])/(1 - Sqrt[1 - 1. (1 - E^(-NN^x2 x1))])]/(2 Sqrt[ 1 - 1. (1 - E^(-NN^x2 x1))])))/(1 - 1. (1 - E^(-NN^x2 x1))))/NN], 0]; objective = Sum[diff^2, {NN, 1, 20}]; NMinimize[{objective, x1 > 0, x1 < 20, x2 > 0, x2 < 10}, {x1, x2}] 

{7.50014*10^8, {x1 -> 0.00448925, x2 -> 0.814362}}

Of course, there is no guaranty that the global minimum is found.

$\endgroup$
3
  • $\begingroup$ Thank you for the comment. The solution proposed does not work on Win 10, Mathematica ver. 13.0.1. $\endgroup$ Commented Jun 27, 2024 at 17:31
  • $\begingroup$ @seva011: Up to the documentation to NMinimize (see the bottom of the page), the command was updated in 2022 (13.2). $\endgroup$ Commented Jun 27, 2024 at 17:45
  • $\begingroup$ Got it, but currently I have no opportunity to update it. So looking for other means. $\endgroup$ Commented Jun 27, 2024 at 18:20

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.