Grazie ... ho trovato qualcos'altro da aggiungere ai compiti per le vacanze
BTW dato che ci sei ... non potresti provare anche con gli ultimi 9 punti postati
RenzoDF ha scritto:non potresti provare anche con gli ultimi 9 punti postati

x=c(1,1,1,2,2,2,3,3,3)
y=c(1,2,3,1,2,3,1,2,3)
out=c(3.2,4.4,6.5,2.5,4.7,5.8,5.1,3.6,2.9)
nls(out ~ a1*sin(w1*x)*cos(w2*y)+k, start = list(a1=1,w1=1,w2=1,k=-1))
Nonlinear regression model
model: out ~ a1 * sin(w1 * x) * cos(w2 * y) + k
data: parent.frame()
a1 w1 w2 k
2.6947 -1.2053 0.9129 4.1078
residual sum-of-squares: 0.902xyz ha scritto:La funziona con l'errore minimo che trovato è questa:
IsidoroKZ ha scritto:La funzione di tipo a1 * sin(w1 * x) * cos(w2 * y) + k l'hai scelta tu o l'ha presa il programma da un suo data base di funzioni, cercandone una che fosse ragionevole per quei dati?

x=c(1,1,1,2,2,2,3,3,3)
y=c(1,2,3,1,2,3,1,2,3)
out=c(3.2,4.4,6.5,2.5,4.7,5.8,5.1,3.6,2.9)
nls(out ~ a1*x+a2*x^2+b1*y+b2*y^2+c11*x*y+c21*x^2*y+c12*x*y^2+c22*x^2*y^2+k, start = list(a1=1,a2=1,b1=1,b2=1,c11=1,c21=1,c12=1,c22=1,k=1), algorithm = "port")Nonlinear regression model
model: out ~ a1 * x + a2 * x^2 + b1 * y + b2 * y^2 + c11 * x * y + c21 * x^2 * y + c12 * x * y^2 + c22 * x^2 * y^2 + k
data: parent.frame()
a1 a2 b1 b2 c11 c21 c12 c22 k
-21.550 5.950 -14.700 3.400 19.825 -5.275 -3.925 0.975 18.500
residual sum-of-squares: 4.385e-26
#Dati iniziali
x=c(1,1,1,2,2,2,3,3,3)
y=c(1,2,3,1,2,3,1,2,3)
out=c(3.2,4.4,6.5,2.5,4.7,5.8,5.1,3.6,2.9)
#Ricerca parametri funzione
renzodf<- nls(out ~ c10*x+c20*x^2+c01*y+c02*y^2+c11*x*y+c21*x^2*y+c12*x*y^2+c22*x^2*y^2+k,
start = list(c10=1,c20=1,c01=1,c02=1,c11=1,c21=1,c12=1,c22=1,k=1), algorithm = "port")
#Definizione funzione interpolante
coefficienti<- coef(renzodf)
valore<-function(x,y){cbind( x,x^2,y,y^2,x*y,x^2*y,x*y^2,x^2*y^2,1) %*% coefficienti}
#Plotting 3D
x<-y<-seq(0.5, 3.5, len = 20)
z<-outer(x,y,valore)
persp(x, y, z, main="Electroportal Interpolation",
col="lightgreen", theta=30, phi=20,
r=50, d=0.5, expand=0.5,
ltheta=40, lphi=180,shade=0.75,
cex.axis=0.5,cex.lab=0.7,
xlab = "x", ylab = "y", zlab="z",
ticktype="detailed",nticks=5) #Plotting 3D (OpenGL)
require(rgl)
x<-y<-seq(0.5, 3.5, len = 20)
z<-outer(x,y,valore)
open3d()
bg3d("white")
view3d(theta=0, phi=-70)
persp3d(x, y, z,
xlab="x", ylab="y", zlab="z",
col="lightgreen",
back="line",
smooth=FALSE,
aspect=c(1, 1, 0.5))
#automatic spin
#play3d(spin3d(axis=c(0,0,1), rpm=5), duration=10)
#screen snapshot PNG
#snapshot3d("screen.png", fmt="png")
#screen snapshot EPS
#rgl.postscript("screen.eps", fmt = "eps")
#save animated GIF
#movie3d(spin3d(axis=c(0,0,1), rpm=10), fps=10, duration=5, dir=".", movie="anim3d")Torna a Programmi applicativi: simulatori, CAD ed altro
Visitano il forum: Nessuno e 10 ospiti