Ir ao conteúdo
  • Cadastre-se

Fekatur

Membro Pleno
  • Posts

    56
  • Cadastrado em

  • Última visita

Tudo que Fekatur postou

  1. Fekatur

    Alocação Dinâmica

    Executei essa linha de comando: gcc teste.c -o tes -Wall -pedantic Obtive esses avisos: teste.c: In function ‘main’: teste.c:17:5: warning: ‘return’ with no value, in function returning non-void [-Wreturn-type] return; ^ teste.c:38:1: warning: ISO C90 does not support the ‘%lf’ gnu_printf format [-Wformat=] printf("%lf %lf\n",x,fx); ^ teste.c:38:1: warning: ISO C90 does not support the ‘%lf’ gnu_printf format [-Wformat=]
  2. Fekatur

    Alocação Dinâmica

    Salve Mauro, Realizei a correçao mas o erro persiste. Apos a correçao executei as seguintes linhas de comando: gcc teste.c -o tes -lm ./tes E a saída foi: 1 2 0.000000 0.000000 0.000000 0.000000
  3. Bom dia galera, Código em C. Quando eu defino o tamanho dos vetores, consigo fazer a leitura e impressão dos valores do arquivo corretamente. Porém ao tentar fazer alocação dinâmica os valores impressos não batem. Estou testando com um arquivo de entrada bem simples, duas linha. Primeira linha contém os valores 0 0 e na segunda linha 1 1. A impressão está me retornando apenas zeros. Agradeço a ajuda, segue o código: # include <stdlib.h> # include <stdio.h> int main(){ FILE *arq; double *x,*fx; int i, n=0; char ch; arq = fopen("entrada.txt", "rt"); if (arq == NULL) { printf("Arquivo nao encontrado\n"); return; } do{ ch=fgetc(arq); if(ch=='\n'){ n++; printf("%d\n",n); } }while(ch!= EOF); x=malloc(n * sizeof(double)); fx=malloc(n * sizeof(double)); for(i=0;i<n;i++){ fscanf(arq,"%lf %lf",&x,&fx); printf("%lf %lf\n",x,fx); } fclose(arq); return 0; }
  4. Fekatur

    Spline *****bicos

    Salve galera, Estou com um ep complicado pra fazer e estou recebendo uns erros chatos como: expected '=', ',', ';', 'asm' or '_attribute_' before 'for' Poderiam me dar uma ajuda? Basicamente preciso resolver um sistema linear que resulta em uma matriz tri-diagonal. Estou tentando usar gradiente conjugado para isso. Obrigado Segue o código: #include <stdlib.h> Calculating the Euclidean norm of a vector double normvec(int n, double *vt){ int i; double res=0.; for(i=0; i<n; i++){ res=res+pow(vt,2); } res=sqrt(res); return res; } int main () { int i=0; int nlines=1; int it=1; int stop=0; int k,j,l,ch,itmax; double eps1=0.00000001; double sum1,sum2,sum3,beta,alpha; double**Coef,*I,*x,*fx,*dx,*dxnew,*dxold,*c,*V,*r,*rnew,*rnorm,*pnew,*betha1,*betha2; //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ CÁLCULO DO SPLINE +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ FILE *inputfile; inputfile=fopen("entrada.txt","w"); if(inputfile==NULL){ printf("File does not exist or it was removed: entrada.txt\n"); fclose(inputfile); exit(FAILURE); } do{ ch=fgetc(inputfile); if(ch=='\n'){nlines++;} }while(ch!=EOF); nlines=nlines-1; fclose(inputfile); x=(double *)malloc(nlines*sizeof(double)); fx=(double *)malloc(nlines * sizeof(double)); dx=(double *)malloc(nlines * sizeof(double)); dxnew=(double *)malloc(nlines * sizeof(double)); dxold=(double *)malloc(nlines * sizeof(double)); c=(double *)malloc(nlines * sizeof(double)); V=(double *)malloc( (nlines*nlines) * sizeof(double)); r=(double *)malloc( (nlines*nlines) * sizeof(double)); rnew=(double *)malloc( (nlines*nlines) * sizeof(double)); rnorm=(double *)malloc( (nlines*nlines) * sizeof(double)); pnew=(double *)malloc( (nlines*nlines) * sizeof(double)); betha1=(double *)malloc(nlines * sizeof(double)); betha2=(double *)malloc(nlines * sizeof(double)); inputfile=fopen("entrada.txt","w"); for(i=0;i<nlines;i++){ fscanf(inputfile,"%lf %lf",x,fx); } fclose(inputfile); for(k=0;k<nlines;k++){ c=(fx[i+1]-fx)/(x[i+1]-x);//cálculo de f[xi,x(i+1)] } dx[0]=0; dx[nlines-1]=0; Coef=(double **)malloc((nlines-2) * sizeof(double *)); for(i=0;i<nlines-2;i++){ Coef=(double *)malloc( (nlines-2) * sizeof(double)); } I=(double *)malloc((nlines-2) * sizeof(double *)); //zerando a matrix for(j=0;j<nlines-2;j++){ for(k=0;k<nlines-2;k++){ Coef[j][k]=0.; } } k=0; for(j=1;j<nlines-2;j++){ Coef[j][k]=2*(x[j+1]-x[j-1]); Coef[j][k+1]=x[j]-x[j-1]; Coef[j+1][k]=x[j+2]-x[j+1]; k++; } l=0; for(k=0;k<nlines-2;k++){ I[k]=3*c[k]*(x[k+2]+x[k+1])+3*c[l+k]*(x[k+1]+x[k]); } //Rotina para cáculo das derivadas por gradiente conjugado for(k=0;k<nlines;k++){ dxnew[k]=0.0; } for(i=0;i<nlines;i++){ for(j=0;j<nlines;j++){ sum1=sum1+Coef[j]*dxnew[j]; } r=I-sum1; sum1=0.0; } while(stop==0){ printf("it: %d\n",it); if(it==1){ for(i=0;i<(nlines);i++){ pnew=r; } } else{ sum1=0.0; sum2=0.0; for(i=0;i<(nlines);i++){ sum1=sum1+rnew*rnew; sum2=sum2+r*r; } beta=sum1/sum2; for(i=0;i<(nlines);i++){ pnew=rnew+beta*pnew; } } sum1=0.0; sum2=0.0; sum3=0.0; for(i=0;i<nlines;i++){ for(j=0;j<nlines;j++){ sum1=sum1+pnew[j]*Coef[j]; } sum2=sum2+sum1*pnew; sum1=0.0; sum3=sum3+(rnew*rnew); } alpha=sum3/sum2; sum1=0.0; sum2=0.0; sum3=0.0; for(i=0;i<nlines;i++){ dxnew=dxold+dxold(alpha*pnew);//Qual o vetor relacionado com ?? dxold=dxnew; } for(i=0;i<nlines;i++){ for(j=0;j<(nlines);j++){ sum1=sum1+Coef[j]*dxnew[j]; } r=rnew; rnew=I-sum1; sum1=0.0; } rnorm=normvec(nlines,rnew); if(rnorm<=eps1 || it>=itmax){ stop=1; if(it==itmax){ printf("There was no convergence!\n"); printf("The routine has reached the maximum iteration limit!\n"); printf("Try to run the routine again or verify if the obtained solution is good!\n"); } else{ printf("There was convergence!\n"); printf("The convergence was reached according to the parameters that you have established!\n"); printf("Verify if the solution is good. Otherwise, try it again!\n"); } } } } for(j=0;j<nlines;j++) { betha1[j]=(c[j]-dx[j])/(x[j+1]-x[j]);//c·lculo de (f[xi,x(i+1)-f'(xi))/(x(i+1)-xi) betha2[j]=(dx[j+1]-(2*c[j]])+dx[j])/((x[j+1]-x[j])*(x[j+1]-x[j]));//c·lculo de (f'(xi+1)-2f[xi,x(i+1)+f'(xi))/(x(i+1)-xi)†} //Rotina para impressâo da funÃâo S for(j=0;j<nlines-2;j++) { printf("[x%d,x%d]\n",j,j+1); printf("S = %lf + %lf(x-%lf) + %lf(x-%lf)² + %lf(x-%lf)².(x-%lf)\n\n",fx[j],dx[j],x[j],betha1[j],x[j],betha2[j],x[j],x[j+1]); }
  5. Karaca já mandei tudo que tinha no registro e ainda não ta rolando... Como o jogo foi movido não foi possível excluir normalmente, ai deletei tudo e limpei o registro com programa e manualmente. Formatei a partição e mesmo assim não consigo reinstalar.
  6. Tive que formatar a partição onde tinha o jogo Batman Arkham Asylum. Agora quando coloco o cd para instalar ele fica com o botão Install inativo, como na foto: http://lh6.ggpht.com/_VN7BzHNJJ3E/SsNwDIZK9PI/AAAAAAAAARw/G-af-BnM9Vs/s640/Captura%20de%20tela%20inteira%203092009%20114923.jpg Já usei o programa Revo Unistaler para limpar o registro e mesmo assim ainda não consigo reinstala-lo. O que posso fazer? Agradeço a ajuda.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

Ebook grátis: Aprenda a ler resistores e capacitores!

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!