All pastes #475158 Raw Edit

felix

public cpp v1 · immutable
·published 2007-05-07 08:36 UTC
rendered paste body
/*************************************************************************** *   Copyright (C) 2007 by Félix Robles Elvira   * *   f@ubuntu   * *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * *   This program is distributed in the hope that it will be useful,       * *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * *   GNU General Public License for more details.                          * *                                                                         * *   You should have received a copy of the GNU General Public License     * *   along with this program; if not, write to the                         * *   Free Software Foundation, Inc.,                                       * *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * ***************************************************************************/#ifdef HAVE_CONFIG_H#include <config.h>#endif#include <iostream>#include <cstdlib>#include <iostream>#include <math.h>#define e0 8.8541878176e-12#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679fusing namespace std;class miclase{      public:      double sumq[2];      };inline float p (int i){	return (float)(i%2);}double bi[1000],qi[1000];miclase suma(double r1, double r2, double v1, double v2, double d, bool k);miclase sacarq(double r1, double r2, double v1, double v2, double d);int main (int argc, char *argv[]){	while(1){		double r1, r2, v1,  v2,  d;		cout << "Pi es 3 exactamente: double r1, r2, v1,  v2,  d" << endl;		cin >> r1 >> r2 >> v1 >> v2 >> d;		miclase s = sacarq(r1, r2, v1,  v2,  d);		double c1 = 4*pi*e0*r1;		double c2  = 4*pi*e0*r2;		double c12 = (s.sumq[0]-c1*v1)/v2;		double c21 = (s.sumq[1]-c2*v2)/v1;		cout << "c12 c21 c1 c2: " << c12 << " " << c21 << " " << c1 << " " << c2 << endl;		cout << "q1 q2: " << s.sumq[0] << " " << s.sumq[1]  << endl;	}    system("pause");  return 0;}//Saca las qmiclase sacarq(double r1, double r2, double v1, double v2, double d){	miclase f,s;        f = suma(r1, r2, v1,  v2,  d,0);        s = suma(r1, r2, v1,  v2,  d,1);	cout << "f q1 q2: " << f.sumq[0] << " " << f.sumq[1]  << endl;	cout << "s q1 q2: " << s.sumq[1] << " " << s.sumq[0]  << endl;        f.sumq[0]+=s.sumq[1]; f.sumq[1]+=s.sumq[0];        return f;}miclase suma(double r1, double r2, double v1, double v2, double d, bool k){        miclase s;       if(k)       {    double foo= r1;            r1=r2;            r2=foo;            foo = v1;            v1=v2;            v2=foo;       }       qi[0]= 4*pi*e0*r1*v1;       bi[0]=0;//(r1*r1)/d;       s.sumq[0]=s.sumq[1]=0;	cout << endl << "b0" << ": " << bi[0] << endl;       for(int i =1; i< 30; i++)       {                          bi[i]=( (r1*r1)*((i+1)%2)+(r2*r2)*(i%2)) / (d-bi[i-1]);                /* if(bi[i]<0)                            bi[i]= -bi[i]; */                 cout << endl << "b" << i << ": " << bi[i] << endl;       }       cout << endl << "q0" << ": " << qi[0] << endl;       for(int i =1; i< 30; i++)       {                                    qi[i]=qi[i-1]*( bi[i]-r1*p(i)-r2*p(i+1) )                /(d-bi[i-1]-r1*p(i)-r2*p(i+1));		cout << endl << "q" << i << "= " << qi[i]  << " = ";		cout   <<qi[i-1]<< " *( "<< bi[i] << " - "<< r1 << " * "<<  p(i) << " - "<< r2 << " * "<< p(i+1) << " ) / ( "<<  d<< " - "<< bi[i-1] << " - "<< +r1*p(i)+r2*p(i+1) << " ) "<< endl;               /* if(qi[i]<0)                           qi[i]= -qi[i];*/                       }       for(int i =0; i< 30; i++)       {               //  cout << "s.sumq[0]: " <<  s.sumq[0] << " s.sumq[1]: " <<  s.sumq[1] << endl;               if(i%2 == 0)               {                              s.sumq[0]+=qi[i];               }               else               {                            s.sumq[1]+=qi[i];               }       }       return s;}