[TAREFA] Potencial elétrico: matrizes como espaço discreto
#include <stdio.h>
#include <math.h>
#define nx 100
#define ny 100
#define x0 0.0
#define dx 0.1
#define y0 0.0
#define dy 0.1
#define q 1.0
#define xp 5.01
#define yp 5.01
// x0 e y0 é posição do canto da matriz
// xp e yp é posiçao da particula
int main(void)
{
double M[nx][ny],x,y,V;
int i,j;
M[i][j]=0.0;
x=x0;
y=y0;
for (i=0;i<nx;i++)
{
for(j=0;j<ny;j++)
{
x=x0+dx*i;
y=y0+dy*j;
V=q/(sqrt(pow((x-xp),2)+pow((y-yp),2)));
M[i][j]=V;
printf("%lf \t %lf \t %lf \n",x,y,V);
}
}
return 0;
}
Comments