- 174 名前:卵の名無しさん mailto:sage [2020/07/14(火) 20:06:57.13 ID:bf2JlY+k.net]
- f <- function(x,y){
A=c(1,0) B=c(cos(x),sin(x)) C=c(cos(y),sin(y)) pracma::dot(A-B,A-C) } (opt=optim(par=c(1,1),fn=function(xy)f(xy[1],xy[2]))) round(opt$par*180/pi,1) source('tools.R') f=Vectorize(f) x=y=seq(-pi,pi,length=50) z=outer(x,y,f) contour(x,y,z) rgl::persp3d(x,y,z,col=2) Persp(x,y,z) library(pracma) fn <- function(x,y,z,p=0.5){ A=c(1,0) B=c(cos(x),sin(x)) C=c(cos(y),sin(y)) P=c(p*cos(z),p*sin(z)) dot(P-B,P-C)+dot(P-C,P-A)+dot(P-A,P-B) } g <- function(p){ optim(par=c(1,1,1), fn=function(w) fn(w[1],w[2],w[3],p),method='L')$value } g=Vectorize(g) optimize(g,c(0,1))
|
|