1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

「ニュートン法(2変数)」を参考にWolframAlphaとVBAソルバーとSymPyでやってみたい。

Posted at

オリジナル

wolframalphaで

最小値
(x, y)≈(-2.57025, 2.36873) のとき, min{x^4/2 + x^3/3 - 2 x^2 y + 3 y^2 + 3 x - 1 y + 4}≈-4.38238

極小値
(x, y)≈(-2.57025, 2.36873) のとき, min{x^4/2 + x^3/3 - 2 x^2 y + 3 y^2 + 3 x - 1 y + 4}≈-4.38238
標準の計算時間制限を超えました...

VBAソルバーで

エクセルのソルバーのダイアログ入力で普通にできますが、あえてVBAでチャレンジしてみました。ソルバーのための以下の参考の設定が必要です。
SolverAdd 関数について、微妙ですね。「問題の制約条件を追加します。」難しいです。
おすすめのサイトがあれば、教えて下さい。

参考 

Sub main()
    Range("A1") = ""
    Range("A2") = ""
    Range("A3") = ""
MsgBox "最小値を計算します。(1/2)*x**4+(1/3)*x**3-2*(x**2)*y+3*y**2+3*x-1*y+4"
'
    Range("A3").Formula = "=(1/2)*A1^4+(1/3)*A1^3-2*(A1^2)*A2+3*A2^2+3*A1-1*A2+4"
    Dim ws As Worksheet: Set ws = ActiveSheet
    SolverReset
    SolverOk setCell:=ws.Range("A3"), _
                   MaxMinVal:=2, _
                   ByChange:=ws.Range("A1:A2"), _
                   EngineDesc:="GRG Nonlinear"
    SolverAdd cellRef:=Range("A1"), _
         relation:=1, _
         formulaText:=-2
    SolverAdd cellRef:=Range("A1"), _
         relation:=3, _
         formulaText:=-3
     SolverSolve UserFinish:=True
End Sub
'結果
'-2.570248138
'2.368724738
'-4.38238056

SymPyで

勉強中

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?