Qurak

Numerical nonlinear global optimization examples finding multiple optima method 2

บทแนะนำ 3 ขั้นตอน รันตามลำดับในหนึ่งเซสชัน ทุกขั้นถูกรันกับเอนจินจริง และเอาต์พุตด้านล่างคือสิ่งที่มันให้

ขั้นที่ 1
Clear[f, pts, dots, cplot];
f[x_, y_] := (x^2 + y^2 - 16)^2;
Plot3D[f[x, y], {x, -5, 5}, {y, -5, 5}]
เอาต์พุต
-Graphics3D-
ขั้นที่ 2
{sol, pts} = Reap[
	NMinimize[f[x, y], {{x, -5, 5}, {y, -5, 5}}, Method -> "DifferentialEvolution", EvaluationMonitor :> Sow[{x, y}, "VisitedPoint"]],
	"VisitedPoint"];
sol
เอาต์พุต
NMinimize[(-16 + x^2 + y^2)^2, {{x, -5, 5}, {y, -5, 5}}, Method -> DifferentialEvolution, EvaluationMonitor :> Sow[{x, y}, VisitedPoint]]
ขั้นที่ 3
newpts = Cases[First[pts], x_ /; Abs[f@@x - First[sol]] ≤ .05];
rainbow[a_] := Hue[0.75 a, .5, 1];
dots = Graphics[Join[{PointSize[0.02], RGBColor[1, 1, 1], Point[#]& /@ newpts}, {{PointSize[0.02], RGBColor[0, 0, 0], Point[{x, y} /. Last[sol]]}}]];
cplot = ContourPlot[f[x, y], {x, -5, 5}, {y, -5, 5}, ColorFunction -> rainbow, Contours -> 4Range[0, 10] ^ 2, PlotPoints -> 50];
Show[cplot, dots]
เอาต์พุต
-Graphics-

ฟังก์ชันที่ใช้

สูตรงานที่เกี่ยวข้อง

สูตรงานทั้งหมด · เอกสารอ้างอิงฟังก์ชัน · ใช้สิ่งนี้จากไคลเอนต์ MCP