Não foi possível enviar o arquivo. Será algum problema com as permissões?
Diferenças
Aqui você vê as diferenças entre duas revisões dessa página.
| Ambos lados da revisão anterior Revisão anterior Próxima revisão | Revisão anterior | ||
|
disciplinas:ce709-2010:atividades [2010/10/20 17:56] walmes |
disciplinas:ce709-2010:atividades [2010/10/20 20:01] (atual) walmes |
||
|---|---|---|---|
| Linha 82: | Linha 82: | ||
| curve(opt$par[1]*x/(opt$par[2]+x), add=TRUE, col=2) | curve(opt$par[1]*x/(opt$par[2]+x), add=TRUE, col=2) | ||
| + | |||
| + | #----------------------------------------------------------- | ||
| + | # usando outra função objetivo | ||
| + | |||
| + | fun.objetivo <- function(theta, y, x){ | ||
| + | n <- length(y) | ||
| + | -(-n/2*log(2*pi)-n/2*log(theta[3])- | ||
| + | sum((y-theta[1]*x/(theta[2]+x))^2/(2*theta[3]))) | ||
| + | } | ||
| + | |||
| + | #----------------------------------------------------------- | ||
| + | # os chutes | ||
| + | |||
| + | start <- c(3,0.5,0.1) | ||
| + | |||
| + | #----------------------------------------------------------- | ||
| + | # optimização | ||
| + | |||
| + | opt <- optim(start, fun.objetivo, y=y, x=x) | ||
| + | opt | ||
| + | |||
| + | curve(opt$par[1]*x/(opt$par[2]+x), add=TRUE, col=3) | ||
| + | #----------------------------------------------------------- | ||
| + | |||
| + | #------------------------------------------------------------------------------------------ | ||
| + | |||
| + | library(gWidgetsRGtk2) | ||
| + | |||
| + | da <- data.frame(x=1:20) | ||
| + | da$y <- 10*da$x/(3+da$x)+rnorm(da$x,0,0.2) | ||
| + | plot(y~x, data=da) | ||
| + | |||
| + | #------------------------------------------------------------------------------------------ | ||
| + | |||
| + | limits <- list(A=c(0,20), B=c(0,6), n=c(0,2)) | ||
| + | |||
| + | plotMM <- function(...){ | ||
| + | plot(y~x, data=da) | ||
| + | curve(svalue(A)*x^svalue(n)/(svalue(B)+x), add=TRUE) | ||
| + | } | ||
| + | |||
| + | w <- gwindow("Slider and spinbox example") | ||
| + | |||
| + | tbl = glayout(cont=w) | ||
| + | for(i in 1:length(limits)){ | ||
| + | tbl[i,1] <- paste("Slide to adjuste parameter", names(limits)[i]) | ||
| + | tbl[i,2, expand=TRUE] <- (assign(names(limits)[i], | ||
| + | gslider(from=limits[[i]][1], | ||
| + | to=limits[[i]][2], | ||
| + | by=diff(limits[[i]])/20, | ||
| + | value=mean(limits[[i]]), | ||
| + | container=tbl, handler=plotMM))) | ||
| + | } | ||
| + | |||
| + | plotMM() | ||
| + | |||
| + | #------------------------------------------------------------------------------------------ | ||
| </code> | </code> | ||