Advertisement
luizaspan

[TAREFA] Potencial elétrico: matrizes como espaço discreto

Jun 11th, 2015
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. #define nx 100
  5. #define ny 100
  6.  
  7. #define x0 0.0
  8. #define dx 0.1
  9.  
  10. #define y0 0.0
  11. #define dy 0.1
  12. #define q 1.0
  13.  
  14. #define xp 5.01
  15. #define yp 5.01
  16.  
  17. // x0 e y0 é posição do canto da matriz
  18. // xp e yp é posiçao da particula
  19.  
  20. int main(void)
  21. {
  22.   double M[nx][ny],x,y,V;
  23.   int i,j;
  24.  
  25.   M[i][j]=0.0;
  26.   x=x0;
  27.   y=y0;
  28.  
  29.   for (i=0;i<nx;i++)
  30.     {
  31.       for(j=0;j<ny;j++)
  32.     {
  33.       x=x0+dx*i;
  34.       y=y0+dy*j;
  35.  
  36.       V=q/(sqrt(pow((x-xp),2)+pow((y-yp),2)));
  37.  
  38.       M[i][j]=V;
  39.  
  40.       printf("%lf \t %lf \t %lf \n",x,y,V);
  41.     }
  42.     }
  43.  
  44.   return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement