Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Test de Convergencia para El Desarrollo en Serie de Un Potencial Electrostático
Test de Convergencia para El Desarrollo en Serie de Un Potencial Electrostático
Enrico Bandiello
(Dated: 03/04/2010)
En este ejercicio vamos a ver cómo se comporta, en relación a la convergencia, el desarrollo en
serie de un potencial electrostático bidimensional (es decir, que sólo depende de dos coordenadas).
Para el estudio de dicho potencial se usará un programa en C++ escrito a propósito. El potencial
se evaluará en un grid de 100 × 100 puntos. En primer lugar se averiguarán los lı́mites de cálculo
debidos a los errores de overflow, luego se estudiará la convergencia puntual de la serie que define
el potencial y, en fin, se dibujará el potencial, utilizando los datos de las análisis anteriores.
4 V (−1)n
Φn (x, y) := cos(kxn x) sinh(kxn y) (2)
akxn sinh(kxn b/2)
Figura 2. Número máximo de iteraciones por cada punto Figura 3. Número de iteraciones necesarios para alcanzar, en
(x,y). cada punto (x, y), una precisión de 0.001 V.
Φ(±a/2, y) = 0 V
Φ(x, ±b/2) = ±10 V
V. EL PROGRAMA
#include<cmath>
#include<iostream>
#include<fstream>
#include<iomanip>
#define PI 3.141592653589793
#define V 10.0
#define A 1.0
#define B 0.5
using namespace std;
double k=0.0;
k=(PI/A)*(2*i+1);
return (cos(k*x)*sinh(k*y)*4.0*V*pow(-1.0,i))/(A*k*sinh(k*(B/2)));
}
/*
* This function is used to check the maximum number of iterations
* allowed before the sum goes overflow
*/
return i-1;
}
5
/*
* The following function calculates partial sums up for phi
* to up "n" terms in the (x,y) point.
*/
double phi=0.0;
unsigned int i=0;
while(i<n+1)
{
phi+=term(x,y,i);
i+=1;
}
return phi;
}
int main()
{
// This file contains graph data
ofstream graph("graph.dat");
graph.precision(6);
convergence.precision(6);
int n;
do
{
cout<<"\n\nPlease, input the highest number of iterations that"
<<"will be used in calulation (0<n<10001): ";
cin>>n;
} while(n<1 || n>10000);
/*
* Here we have to check that we’re not calculating th ES
* potential in the vertices of the rectangle, because there it’s
* undefined. So we have to put some constraints. Due to the
* unreliability of abs(), or fabs() functions when used to *compare*
* types other than integers; so, instead of simply comparing
6
double x=0;
double y=0;
while(ix<51)
{
/*
* iy goes up to 50 *only if* fabs(ix)< 50;
* if fabs(ix)=50 then iy stops at -49;
*/
while(iy<50+(fabs(ix)!=50))
{
x=ix*pasox;
y=iy*pasoy;
of=overflow(x,y,n);
maxallowed<of?:maxallowed=of;
maxiter<<x<<"\t"<<y<<"\t"<<of<<"\n";
iy+=1;
}
ix+=1;
iy=-50+(fabs(ix)==50);
/*
* Back to the lowest value compatible with ix.
* iy goes down to 50 *only if* fabs(ix)<50;
* if fabs(ix)=50 then iy stops at -49
*/
maxiter.close();
cout<<"\nMax allowed iterations: "<<maxallowed;
cout<<"\nData for each point is in the file \"maxiter.dat\".";
cout<<"\n\n*** Step 2: Generating graphs ***\n";
7
x=0;
y=0;
ix=-50;
iy=-49;
// epsilon = precision
double epsilon=0.001;
double deltav=0;
while(ix<51)
{
while(iy<50+(fabs(ix)!=50))
{
x=ix*pasox;
y=iy*pasoy;
numiter=0;
while((deltav=fabs(fabs(term(x,y,numiter+1))-fabs(term(x,y,numiter))))>epsilon)
{
numiter=numiter+1;
}
convergence<<x<<"\t"<<y<<"\t"<<numiter<<"\t"<<"\n";
graph<<x<<"\t"<<y<<"\t"<<sumpart(x,y,maxallowed)<<"\n";
graphcon<<x
<<"\t"
<<y<<"\t"
<<fabs(fabs(sumpart(x,y,maxallowed))-fabs(sumpart(x,y,numiter)))<<"\n";
iy+=1;
}
ix+=1;
iy=-50+(fabs(ix)==50);
}
convergence.close();
graph.close();
graphcon.close();
return 0;
}