c=c(8, 1, 1, 0, 2, 0, 9, 2, 1, 1, 2, 1, 11,2, 0, 3, 2, 1, -8, 1, 2, 1, 2, 3, 10)
A=matrix(c,5,5,,byrow=TRUE);print("Matriz A"); A

tr<-function(A){  # Função traço
p=0; n=length(A[1,])
for ( i in 1:n ){p=p+A[i,i]}
p}  
   
coef<-function(A){ # Calculo dos coeficientes
n=length(A[1,]);    a=0*1:(n+1)
s=0*1:n; s[1]=tr(A)
a[1]=1;a[2]=-s[1]; B=A
for ( i in 2:n){B=B%*%A; s[i]=tr(B); q=0
for (j in 1:i){q=q+a[j]*s[i+1-j]}; a[i+1]=-q/i}
a=(-1)^n*a;a}
coe=coef(A);print("Coeficientes do polinomio Caracteristico");coe     

policarac<-function(s){
p=coe[n]
    for (i in 1:(n-1)){p=p+coe[i]*s^(n-i)}
    p
}

curve(policarac,-5,5)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: