Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
180 views
in Technique[技术] by (71.8m points)

Finding the minimum of a function in R

I want to prove that x = [-9/22 & -2/11] is a minimum of the following function attached in the following figure: Function

I wrote the following code in R. Is it correct?

f = function(x, y) 3+2*x+3*y+2*x^2+2*x*y+6*y^2
x = seq(-5, 5, 0.1)
y = seq(-5, 5, 0.1)
z = outer(x, y, f)
persp(x, y, z, theta=45, phi=45)

library(matrixcalc)
f = expression(3+2*x+3*y+2*x^2+2*x*y+6*y^2)

eval(D(f, "x"), list(x=-9/22, y=-2/11))

A = optimHess(c(-9/22, -2/11),
                  function(x) 3+2*x[1]+3*x[2]+2*x[1]^2+2*x[1]*x[2]+6*x[2]^2,
                  control=(ndeps=0.0001))
is.negative.definite(A)

Moreover... I am pretty new to R. Is there any way to have/name the function as x1 and x2, instead of x and y?

question from:https://stackoverflow.com/questions/65903722/finding-the-minimum-of-a-function-in-r

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...