Advertisement
machkovskitomche

gsl_matrix2k17/2k18Ikolok

Apr 7th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.39 KB | None | 0 0
  1. #include<stdio.h.>
  2. #include<stdlib.h>
  3. #include<gsl/gsl_matrix.h>
  4. #include<gsl/gsl_vector.h>
  5. #include<gsl/gsl_rng.h>
  6. #include<time.h>
  7.  
  8. int main()
  9. {
  10. int N,M,K,i,j,broj;
  11. gsl_matrix *m,*m2;
  12. gsl_vector *v;
  13. printf("Vnesete vrednost za N i M:\t");
  14. scanf("%d %d",&N,&M);
  15. m=gsl_matrix_alloc(N,M);
  16. printf("Vnesete go K");
  17. scanf("%d",&K);
  18. v=gsl_vector_alloc(K);
  19. for(i=0;i<N;i++);
  20. {
  21.     for(j=0;j<M;j++)
  22.     {
  23.         printf("Vnesete gi broevite vo matricata: \n");
  24.         scanf("%d",&broj);
  25.         gsl_matrix_set(m,i,j,broj);
  26.     }
  27. }
  28. printf("Pocetnata matrica e:\n");
  29. for(i=0;i<N;i++)
  30. {
  31.     for(j=0;j<M;j++)
  32.     {
  33.         printf("%g",gsl_matrix_get(m,i,j));
  34.     }
  35. }
  36. int x,y,k,l;
  37. for(i=0;i<K;i++)
  38. {
  39.     printf("Vnesi i,j par za odreduvanje na pozicija: \n");
  40.     scanf("%d%d",&x,&y);
  41.     if(x==N-1||y==M-1)
  42.     {
  43.         gsl_vector_set(v,i,-1);
  44.     }
  45.     else
  46.     {
  47.         gsl_matrix *pom;
  48.         pom=gsl_matrix_alloc(2,2);
  49.         for(k=0;k<2;k++)
  50.         {
  51.             for(l=0;l<2;l++)
  52.             {
  53.                 gsl_matrix_set(pom,k,l,gsl_matrix_get(m,x+k,y+l));
  54.             }
  55.         }
  56.         gsl_vector_set(v,i,gsl_matrix_max(pom));
  57.         gsl_matrix_free(pom);
  58.     }
  59. }
  60.     printf("Krajniot vektor izgleda vaka:\n");
  61.     for(i=0;i<K;i++)
  62.     {
  63.         printf("%g",gsl_vector_get(v,i));
  64.     }
  65.    
  66. gsl_matrix_free(m);
  67. gsl_vector_free(v);
  68.  return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement