Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Interb-04-03-21
f<-function(s){log(s^2*sin(s) + cos(s))} curve(f,0,1) x=seq(0,1,by=0.1);x y=f(x);y plot(x,y) # Supomos y=f(x) e que f(x_i)=p(x_i), em que p(s)=a_0+a_1s+a_2s^2+a_3s^3+a_4s^4 é um polinômio. # Podemos resolver esse problema resolvendo o sistema linear # Au=y # em que a matriz A tem coluna i dada pelo vetor (1,x_i,x_i^2,...,x_i^(n-1)). n=length(x) A=matrix(0,n,n) for ( i in 1:n){ for (j in 1:n){ A[i,j]=x[i]^(j-1) } } A gradconj<-function(A,b,m){ # Início do método B=t(A)%*%A; bb=t(A)%*%b # Adaptando o sistema para A*Au=A*v, ou Bu=b, em que B=A*A é positiva definida e b=A*v. u=0*b w=B%*%u-bb # w0 v=w # d1 alpha= t(w)%*%w /(t(B%*%w) %*%w); alpha=alpha[1] # Escolha de h0 u=u-alpha*w # u1 for ( j in 1:m){ w=(B%*%u-bb) beta=t(B%*%w) %*%v/(t(B%*%v) %*%v); beta=beta[1] v=w-beta*v # Método de Euler alpha= t(v) %*%w/(t(B%*%v) %*%v);alpha=alpha[1] u=u-alpha*v # Método quase Euler (integral) } return(u) } print(" Aproximação para u");u=gradconj(A,y,50);u print("Erro em Au-y"); A%*%u-y #--------------------------------------------------------------------------------------- poli<-function(s){ q=u[1] for (i in 2:n){q=q+u[i]*s^(i-1)} q } curve(poli,min(x),max(x)) # Teste de ajuste points(x,y,col="red") Erro<-function(s){f(s)-poli(s)} curve(Erro,0,1)
run
|
edit
|
history
|
help
0
Sierpinski curve
Practica1
Polynomial Regression with Interaction Terms
This is python
K
Paired t-test [Access Medical Information]
Chi Square Tests [Is the die fair?]
16-09-2020ExVitor
Hiring Discrimination
l