Notices
Results 1 to 11 of 11

Thread: Algebraic objects

  1. #1 Algebraic objects 
    Forum Freshman
    Join Date
    Nov 2013
    Posts
    11
    1) Each object-aside must first elementary plus, minus, multiplication, and division, as well as an end in itself.

    2) The objects implement the terms:

    a * b = b * a
    a / b = c <=> a = b * c
    abs (a) * abs (b) = abs (a * b)


    Now all the trivial conditions hold also automatically correct. for example:

    0 + a = a + 0
    1 * a = a
    a + (-a) = 0
    etc...

    *********

    The definition must be simple and effective. The previous object-oriented variations of the definition follows that all functions are correct, the accessible series (elementary) through. for example:

    a = object rnd ()
    b = sin (a)
    c = arcsin (b)

    Now a is certainly equal to c.

    As soon as I add the real object.


    Reply With Quote  
     

  2.  
     

  3. #2  
    Forum Freshman
    Join Date
    Nov 2013
    Posts
    11
    Algebra algorithms, such kits are constants, and its objects to describe any type. One of the most beautiful algebra formulas is the least-squares polynomial fit:

    Code:
    k0∑xj^0 + k1∑xj^1 + k2∑xj^2 +,...,+ kn∑xj^(n+0) = ∑yjxj^0
    
    k0∑xj^1 + k1∑xj^2 + k2∑xj^3 +,...,+ kn∑xj^(n+1) = ∑yjxj^1
    
    k0∑xj^2 + k1∑xj^3 + k2∑xj^4 +,...,+ kn∑xj^(n+2) = ∑yjxj^2
    ...
    k0∑xj^n + k1∑xj^(n+1) + k2∑xj^(n+2) +,...,+ kn∑xj^(n+n) = ∑yjxj^n
    If object placed in the formula is valid and self with the balance, algebra deals with the substance of the most reasonable results, otherwise not.

    Show, among other things, the least-squares formula that multi-dimensional algebraic objects provide meaningful results.

    Note that 0 ^ 0 = 1, the formula will not work otherwise.


    Reply With Quote  
     

  4. #3  
    KJW
    KJW is offline
    Forum Professor
    Join Date
    Jun 2013
    Posts
    1,213
    Quote Originally Posted by fat ass View Post
    Note that 0 ^ 0 = 1, the formula will not work otherwise.
    is an indeterminate form. It cannot be defined in a universally applicable manner. This doesn't mean that it can't be evaluated under particular circumstances, but that no single evaluation will work under all circumstances. Thus, one cannot impose a particular definition on .
    There are no paradoxes in relativity, just people's misunderstandings of it.
    Reply With Quote  
     

  5. #4  
    Forum Freshman
    Join Date
    Nov 2013
    Posts
    11
    Code:
    /******************************************************************************
    The following program is simple. At the end of a small main that will test    *
    your the validity of the elementary operations.                               *
                                                                                  *
    DIM can be 1, 2, 4, 8, ...                                                    *
    ******************************************************************************/
    
    #include <stdio.h>
    
    class areal
    {
       public:
    
       #define DIM 8
       double f[DIM];
    
       areal(void);
       areal(double*);
       areal(char*, ...);
    
       friend void print(areal);
       friend double abs(areal);
       friend double abs(double);
    
       friend areal operator-(areal);
       friend areal operator+(areal, areal);
       friend areal operator-(areal, areal);
    
       friend areal operator*(areal, areal);
       friend areal operator*(double, areal);
       friend areal operator*(areal, double);
    
       friend areal operator/(areal, areal);
       friend areal operator/(double, areal);
       friend areal operator/(areal, double);
    
       /* mgn=magnitude of */
       friend double mgn(areal c);
       friend void mem00set(void*, int);
    };
    
    void mem00set(void *ptr, int kpl)
    {
       char *c=(char*)ptr;
       for (int i=0; i<kpl; i++)
       c[i]=(char)0;
    }
    
    int strToInt(char *m)
    {
       int x[8]; // max=2^16
       int sum=0, i, j, k=0x01;
       mem00set(x, sizeof(int)*8);
    
       for (i=0, j=0; m[i]; i++)
       if (m[i]>='0'&&m[i]<='9')
       {
          x[j]=(int)(m[i]-'0');
          k*=(int)10;
          ++j;
       }
    
       for (i=0, k/=10; k; i++, k/=10)
       sum+=(int)(x[i]*k);
       return sum;
    }
    
    areal::areal(void)
    {
       mem00set(this, sizeof(areal));
    }
    
    areal::areal(double *a)
    {
       for (int i=0; i<DIM; i++)
       f[i]=a[i];
    }
    
    /******************************************************************************
    Builder areal(char*, ...)                                                     *
                                                                                  *
                                                                                  *
    for example:                                                                  *
                                                                                  *
    areal x("2d", 2, 3), x has the value (2.00000, 3.00000)                       *
    areal y("2f", 1.23, 4.56), y has the value (1.23, 4.56)                       *
                                                                                  *
    - format, the number of figures is given first, exsample 4                    *
    - d means that the numbers given in integer (int) numbers.                    *
    - f means that the numbers given in the form of a floating point number.      *
    ******************************************************************************/
    areal::areal(char *m, ...)
    {
       int sizeofint=sizeof(int);
       int i, j, kpl=strToInt(m), step;
       mem00set((void*)this, sizeof(areal));
       unsigned long P=(unsigned long)&m+sizeof(char*);
    
       for (j=0; m[j]; j++)
       {
          if (m[j]=='d') step=sizeof(int);
          if (m[j]=='f') step=sizeof(double);
       }
    
       step=step==sizeofint? sizeofint: sizeof(double);
       for (i=j=0x00; i<kpl; i++, P+=step)
       f[i] = step == sizeof(int)?
       *(int*)P: *(double*)P;
    }
    
    double abs(double x)
    {
       return x<0.0? -x: x;
    }
    
    double abs(areal a)
    {
       double sum=0.00;
       for (int i=0; i<DIM; i++)
       {
          if (i & 1) sum-=a.f[i];
          else /*~*/ sum+=a.f[i];
       }
       return abs(sum);
    }
    
    double mgn(areal a)
    {
       double sum=0.00;
       for (int i=0; i<DIM; i++)
       sum+=abs(a.f[i]);
       return sum;
    }
    
    areal operator-(areal a)
    {
       for (int i=0; i<DIM; i++)
       a.f[i]=-a.f[i];
       return a;
    }
    
    areal operator+(areal a, areal b)
    {
       for (int i=0; i<DIM; i++)
       a.f[i]+=b.f[i];
       return a;
    }
    
    areal operator-(areal a, areal b)
    {
       for (int i=0; i<DIM; i++)
       a.f[i]-=b.f[i];
       return a;
    }
    
    areal operator*(areal a, areal b)
    {
       double x[DIM*2];
       double y[DIM*2];
       double t[DIM*2];
    
       mem00set(x, sizeof(double)*DIM*2);
       mem00set(y, sizeof(double)*DIM*2);
       mem00set(t, sizeof(double)*DIM*2);
    
       for (int i=0; i<DIM; i++)
       {
          x[i*2]=a.f[i];
          y[i*2]=b.f[i];
       }
    
       for (int i=0; i<DIM*2; i++)
       for (int j=0; j<DIM*2; j++)
       t[i^j]+=x[i]*y[j];
    
       for (int i=0; i<DIM; i++)
       {
          t[i]=t[i*2]-t[i*2+1];
       }
    
       return areal(t);
    }
    
    areal operator*(double k, areal b)
    {
       areal a("1f", k);
       return a*b;
    }
    
    areal operator*(areal a, double k)
    {
       areal b("1f", k);
       return a*b;
    }
    
    areal operator/(double k, areal b)
    {
       areal a("1f", k);
       return a/b;
    }
    
    areal operator/(areal a, double k)
    {
       areal b("1f", k);
       return a/b;
    }
    
    areal operator/(areal u, areal v)
    {
       double x[DIM*2];
       double y[DIM*2];
    
       mem00set(x, sizeof(double)*DIM*2);
       mem00set(y, sizeof(double)*DIM*2);
    
       for (int i=0; i<DIM; i++)
       {
          x[i*2]=u.f[i];
          y[i*2]=v.f[i];
       }
    
       double X[DIM*2];
       #define DIM2 (DIM*2)
       double K[DIM2*DIM2+DIM2];
    
       for (int n=0, p=0; n<DIM*2; n++)
       {
          for (int i=0; i<DIM*2; i++)
          for (int j=0; j<DIM*2; j++)
          {
             if (n == (i^j))
             {
                K[p]=y[j]; ++p;
             }
          }
          K[p]=x[n]; ++p;
       }
    
       // gsolve solves the linear system of equations
       // Gaussian elimination method ...
       int gsolve(double*, double*, int);
    
       gsolve(X, (double*)K, DIM*2);
       for (int i=0; i<DIM; i++)
       X[i]=X[i*2]-X[i*2+1];
       return areal(X);
    }
    
    /******************************************************************************
    qsolve the return value:                                                      *
    1 <=> group was the solution to the equation                                  *
    0 <=> equation group there was no solution.                                   *
    ******************************************************************************/
    int gsolve(double *X, double *f, int n)
    {
       double k, J;
       double *max, *mux;
       int i, j, x, M=(int)n+1;
       void swapRows(double*, double*, int);
    
       for (i=0; i<n-1; i++)
       {
          max=f+i+i*M;
          for (j=i+0x01; j < n; j++)
          if (abs(*(mux=f+i+j*M))>abs(*max)) max=mux;
    
          if (max!=(mux=f+i+i*M))
          swapRows(max, mux, M-i);
    
          if (abs(J=f[i+i*M])<(double)1e-15)
          return 0; /*There is no solution*/
    
          for (j=i+1; j<n; j++)
          {
             if (f[i+j*M])
             {
                k=-f[i+j*M]/J;
                for (x=i+1; x<M; x++)
                f[x+j*M]=f[x+j*M]+k*f[x+i*M];
             }
          }
       }
    
       for (i=n-1; i>=0; i--)
       {
          k=(double)f[n+i*M];
          for (j=n-1; j > i; j--)
          k=k-(double)(X[j]*f[j+i*M]);
    
          if (abs(J=f[i+i*M])<(double)1e-15)
          return 0; /* There is no solution */
          else X[i]=k/J; /* is the solution */
       }
    
       return 1;
    }
    
    void swapRows(double *a, double *b, int n)
    {
       for (int i=0; i<n; i++)
       {
          double tmp=a[i];
          a[i] = b[i];
          b[i]=tmp;
       }
    }
    
    void print(areal a)
    {
       for (int i=0; i<DIM; i++)
       {
          if (!i) printf("(");
          printf("%0.5f", a.f[i]);
          if (i+1==DIM) printf(")\n");
          else printf(", ");
       }
    }
    
    /* ** *** *** ** DEBUG ** *** *** ** DEBUG ** *** *** ** DEBUG ** *** *** ** */
    /* ** *** *** ** DEBUG ** *** *** ** DEBUG ** *** *** ** DEBUG ** *** *** ** */
    /* ** *** *** ** DEBUG ** *** *** ** DEBUG ** *** *** ** DEBUG ** *** *** ** */
    
    // generated random number
    unsigned long rnd(unsigned long max)
    {
       static unsigned long R16A=1L;
       static unsigned long R16B=2L;
       R16A -= 0x012357bfL;
       R16B += 0xfedca201L;
       R16A += (R16A>>16)^(R16B<<16);
       R16B -= (R16A<<16)^(R16B>>16);
       return (R16A^R16B)%max;
    }
    
    // generated random number
    double drand(void)
    {
       unsigned long jak=0xfffffffb;
       double sg=rnd(0x02)? -1: 1;
       double x=(double)rnd(jak);
       return sg * x/(double)jak;
    }
    
    // generated random number
    areal areal_rnd(void)
    {
       double x[DIM];
       for (int i=0; i<DIM; i++)
       x[i]=drand();
       return areal(x);
    }
    
    #pragma argsused
    int main(int kpl, char* asia[])
    {
       for (int i=0; i<16; i++)
       {
          areal a=areal_rnd();
          areal b=areal_rnd();
    
          printf("condition 1: a*b = b*a   \n");
          print(a*b);
          print(b*a);
          printf("\n");
    
          printf("condition 2: a/b=c <=> a=b*c   \n");
          areal c=a/b;
          print(a);
          print(b*c);
          printf("\n");
    
          printf("condition 3: abs(a)*abs(b) = abs(a*b)   \n");
          printf("%0.9f\n", abs(a)*abs(b));
          printf("%0.9f\n", abs(a*b));
          printf("\n");
    
          printf("condition 4: abs(a)/abs(b) = abs(a/b)   \n");
          printf("%0.9f\n", abs(a)/abs(b));
          printf("%0.9f\n", abs(a/b));
          printf("\n");
       }
    
       return 0;
    }
    Reply With Quote  
     

  6. #5  
    Forum Freshman
    Join Date
    Nov 2013
    Posts
    11
    Quote Originally Posted by KJW View Post
    Quote Originally Posted by fat ass View Post
    Note that 0 ^ 0 = 1, the formula will not work otherwise.
    is an indeterminate form. It cannot be defined in a universally applicable manner. This doesn't mean that it can't be evaluated under particular circumstances, but that no single evaluation will work under all circumstances. Thus, one cannot impose a particular definition on .
    lim (x ^ 0) = 1, when x approaches zero. Why it should be set at zero discontinuous change. At least, for example, the generation of the least-squares have to accept that 0 ^ 0 = 1, since otherwise the function description fails.
    Reply With Quote  
     

  7. #6  
    KJW
    KJW is offline
    Forum Professor
    Join Date
    Jun 2013
    Posts
    1,213
    Quote Originally Posted by fat ass View Post
    lim (x ^ 0) = 1, when x approaches zero.
    And lim (0 ^ x) = 0 as x approaches zero. That is my point. Two different limits means that there cannot be a unique definition.
    There are no paradoxes in relativity, just people's misunderstandings of it.
    Reply With Quote  
     

  8. #7  
    Forum Freshman
    Join Date
    Nov 2013
    Posts
    11
    (C/C++) Programs to be more in the future, and I will try to keep its shape simple so that everyone can as quickly as possible to try and apply.


    Regards:

    fat ass
    Reply With Quote  
     

  9. #8  
    Forum Freshman
    Join Date
    Nov 2013
    Posts
    11
    The maximum dimension of the text can be 10000 characters. I need to start a modular code insertion. Each of the new code module is suitable for the earlier code modules.

    Code turns every C / C++ compiler. Begin to bring everything from the beginning, so that first comes to module 1, then module 2, etc..
    Reply With Quote  
     

  10. #9  
    Forum Freshman
    Join Date
    Nov 2013
    Posts
    11
    This is the first module. Save it as "areal.h" to the folder where you want to work. Then you add debug.cpp unit.
    Code:
    #ifndef __AREAL_H
    #define __AREAL_H
    
    /******************************************************************************
    * The following program is simple. At the end of a small main that will test  *
    * your the validity of the elementary operations.                             *
    *                                                                             *
    * Important: DIM can be 1, 2, 4, 8, ...                                       *
    *                                                                             *
    * History:                                                                    *
    * ========                                                                    *
    *                                                                             *
    * 03.12.13 added to the Builder areal(int).                                   *
    * 03.12.13 added to the Builder areal(double).                                *
    * 03.12.13 added to the Builder areal(double, double).                        *
    ******************************************************************************/
    
    class areal
    {
       public:
    
       #define DIM 2
       double f[DIM];
    
       areal(void);
       areal(int q);
       areal(double);
       areal(double*);
       areal(char*, ...);
       areal(double, double);
    
       friend void print(areal);
       friend double abs(areal);
       friend double abs(double);
    
       friend areal operator-(areal);
       friend areal operator+(areal, areal);
       friend areal operator-(areal, areal);
    
       friend areal operator*(areal, areal);
       friend areal operator*(double, areal);
       friend areal operator*(areal, double);
    
       friend areal operator/(areal, areal);
       friend areal operator/(double, areal);
       friend areal operator/(areal, double);
    
       /* mgn=magnitude of */
       friend double mgn(areal c);
       friend void mem00set(void*, int);
    };
    
    void mem00set(void *ptr, int kpl)
    {
       char *c=(char*)ptr;
       for (int i=0; i<kpl; i++)
       c[i]=(char)0;
    }
    
    int strToInt(char *m)
    {
       int x[8]; // max=2^16
       int sum=0, i, j, k=0x01;
       mem00set(x, sizeof(int)*8);
    
       for (i=0, j=0; m[i]; i++)
       if (m[i]>='0'&&m[i]<='9')
       {
          x[j]=(int)(m[i]-'0');
          k*=(int)10;
          ++j;
       }
    
       for (i=0, k/=10; k; i++, k/=10)
       sum+=(int)(x[i]*k);
       return sum;
    }
    
    areal::areal(void)
    {
       mem00set(this, sizeof(areal));
    }
    
    areal::areal(double *a)
    {
       for (int i=0; i<DIM; i++)
       f[i]=a[i];
    }
    
    areal::areal(int q)
    {
       mem00set(this, sizeof(areal));
       f[0]=q;
    }
    
    areal::areal(double a)
    {
       mem00set(this, sizeof(areal));
       f[0]=a;
    }
    
    areal::areal(double a, double b)
    {
       mem00set(this, sizeof(areal));
       f[0]=a; f[1]=b;
    }
    
    /******************************************************************************
    * Builder areal(char*, ...)                                                   *
    *                                                                             *
    *                                                                             *
    * for example:                                                                *
    *                                                                             *
    * areal x("2d", 2, 3), x has the value (2.00000, 3.00000)                     *
    * areal y("2f", 1.23, 4.56), y has the value (1.23, 4.56)                     *
    *                                                                             *
    * - format, the number of figures is given first, exsample 2                  *
    * - d means that the numbers given in integer (int) numbers.                  *
    * - f means that the numbers given in the form of a floating point number.    *
    ******************************************************************************/
    areal::areal(char *m, ...)
    {
       int sizeofint=sizeof(int);
       int i, j, kpl=strToInt(m), step;
       mem00set((void*)this, sizeof(areal));
       unsigned long P=(unsigned long)&m+sizeof(char*);
    
       for (j=0; m[j]; j++)
       {
          if (m[j]=='d') step=sizeof(int);
          if (m[j]=='f') step=sizeof(double);
       }
    
       step=step==sizeofint? sizeofint: sizeof(double);
       for (i=j=0x00; i<kpl; i++, P+=step)
       f[i] = step == sizeof(int)?
       *(int*)P: *(double*)P;
    }
    
    double abs(double x)
    {
       return x<0.0? -x: x;
    }
    
    double abs(areal a)
    {
       double sum=0.00;
       for (int i=0; i<DIM; i++)
       {
          if (i & 1) sum-=a.f[i];
          else /*~*/ sum+=a.f[i];
       }
       return abs(sum);
    }
    
    double mgn(areal a)
    {
       double sum=0.00;
       for (int i=0; i<DIM; i++)
       sum+=abs(a.f[i]);
       return sum;
    }
    
    areal operator-(areal a)
    {
       for (int i=0; i<DIM; i++)
       a.f[i]=-a.f[i];
       return a;
    }
    
    areal operator+(areal a, areal b)
    {
       for (int i=0; i<DIM; i++)
       a.f[i]+=b.f[i];
       return a;
    }
    
    areal operator-(areal a, areal b)
    {
       for (int i=0; i<DIM; i++)
       a.f[i]-=b.f[i];
       return a;
    }
    
    areal operator*(areal a, areal b)
    {
       double x[DIM*2];
       double y[DIM*2];
       double t[DIM*2];
    
       mem00set(x, sizeof(double)*DIM*2);
       mem00set(y, sizeof(double)*DIM*2);
       mem00set(t, sizeof(double)*DIM*2);
    
       for (int i=0; i<DIM; i++)
       {
          x[i*2]=a.f[i];
          y[i*2]=b.f[i];
       }
    
       for (int i=0; i<DIM*2; i++)
       for (int j=0; j<DIM*2; j++)
       t[i^j]+=x[i]*y[j];
    
       for (int i=0; i<DIM; i++)
       {
          t[i]=t[i*2]-t[i*2+1];
       }
    
       return areal(t);
    }
    
    areal operator*(double k, areal b)
    {
       areal a("1f", k);
       return a*b;
    }
    
    areal operator*(areal a, double k)
    {
       areal b("1f", k);
       return a*b;
    }
    
    areal operator/(double k, areal b)
    {
       areal a("1f", k);
       return a/b;
    }
    
    areal operator/(areal a, double k)
    {
       areal b("1f", k);
       return a/b;
    }
    
    areal operator/(areal u, areal v)
    {
       double x[DIM*2];
       double y[DIM*2];
    
       mem00set(x, sizeof(double)*DIM*2);
       mem00set(y, sizeof(double)*DIM*2);
    
       for (int i=0; i<DIM; i++)
       {
          x[i*2]=u.f[i];
          y[i*2]=v.f[i];
       }
    
       double X[DIM*2];
       #define DIM2 (DIM*2)
       double K[DIM2*DIM2+DIM2];
    
       for (int n=0, p=0; n<DIM*2; n++)
       {
          for (int i=0; i<DIM*2; i++)
          for (int j=0; j<DIM*2; j++)
          {
             if (n == (i^j))
             {
                K[p]=y[j]; ++p;
             }
          }
          K[p]=x[n]; ++p;
       }
    
       // gsolve solves the linear system of equations
       // Gaussian elimination method ...
       int gsolve(double*, double*, int);
    
       gsolve(X, (double*)K, DIM*2);
       for (int i=0; i<DIM; i++)
       X[i]=X[i*2]-X[i*2+1];
       return areal(X);
    }
    
    /******************************************************************************
    * qsolve the return value:                                                    *
    *    1 <=> group was the solution to the equation                             *
    *    0 <=> equation group there was no solution.                              *
    ******************************************************************************/
    int gsolve(double *X, double *f, int n)
    {
       double k, J;
       double *max, *mux;
       int i, j, x, M=(int)n+1;
       void swapRows(double*, double*, int);
    
       for (i=0; i<n-1; i++)
       {
          max=f+i+i*M;
          for (j=i+0x01; j < n; j++)
          if (abs(*(mux=f+i+j*M))>abs(*max)) max=mux;
    
          if (max!=(mux=f+i+i*M))
          swapRows(max, mux, M-i);
    
          if (abs(J=f[i+i*M])<(double)1e-15)
          return 0; /*There is no solution*/
    
          for (j=i+1; j<n; j++)
          {
             if (f[i+j*M])
             {
                k=-f[i+j*M]/J;
                for (x=i+1; x<M; x++)
                f[x+j*M]=f[x+j*M]+k*f[x+i*M];
             }
          }
       }
    
       for (i=n-1; i>=0; i--)
       {
          k=(double)f[n+i*M];
          for (j=n-1; j > i; j--)
          k=k-(double)(X[j]*f[j+i*M]);
    
          if (abs(J=f[i+i*M])<(double)1e-15)
          return 0; /* There is no solution */
          else X[i]=k/J; /* is the solution */
       }
    
       return 1;
    }
    
    void swapRows(double *a, double *b, int n)
    {
       for (int i=0; i<n; i++)
       {
          double tmp=a[i];
          a[i] = b[i];
          b[i]=tmp;
       }
    }
    
    #include <stdio.h>
    
    void print(areal a)
    {
       for (int i=0; i<DIM; i++)
       {
          if (!i) printf("(");
          printf("%0.5f", a.f[i]);
          if (i+1==DIM) printf(")\n");
          else printf(", ");
       }
    }
    
    #endif  /* __AREAL_H */
    Code:
    #pragma hdrstop
    
    /*********************************************/
    #include "areal.h" /* ** *** Module 1 *** ** */
    /*********************************************/
    
    /* ** *** *** ** DEBUG ** *** *** ** DEBUG ** *** *** ** DEBUG ** *** *** ** */
    /* ** *** *** ** DEBUG ** *** *** ** DEBUG ** *** *** ** DEBUG ** *** *** ** */
    /* ** *** *** ** DEBUG ** *** *** ** DEBUG ** *** *** ** DEBUG ** *** *** ** */
    
    // generated random number
    unsigned long rnd(unsigned long max)
    {
       static unsigned long R16A=1L;
       static unsigned long R16B=2L;
       R16A -= 0x012357bfL;
       R16B += 0xfedca201L;
       R16A += (R16A>>16)^(R16B<<16);
       R16B -= (R16A<<16)^(R16B>>16);
       return (R16A^R16B)%max;
    }
    
    // generated random number
    double drand(void)
    {
       unsigned long jak=0xfffffffb;
       double sg=rnd(0x02)? -1: 1;
       double x=(double)rnd(jak);
       return sg * x/(double)jak;
    }
    
    // generated random number
    areal areal_rnd(void)
    {
       double x[DIM];
       for (int i=0; i<DIM; i++)
       x[i]=drand();
       return areal(x);
    }
    
    #pragma argsused
    int main(int kpl, char* asia[])
    {
       for (int i=0; i<16; i++)
       {
          areal a=areal_rnd();
          areal b=areal_rnd();
    
          printf("condition 1: a*b = b*a   \n");
          print(a*b);
          print(b*a);
          printf("\n");
    
          printf("condition 2: a/b=c <=> a=b*c   \n");
          areal c=a/b;
          print(a);
          print(b*c);
          printf("\n");
    
          printf("condition 3: abs(a)*abs(b) = abs(a*b)   \n");
          printf("%0.9f\n", abs(a)*abs(b));
          printf("%0.9f\n", abs(a*b));
          printf("\n");
    
          printf("condition 4: abs(a)/abs(b) = abs(a/b)   \n");
          printf("%0.9f\n", abs(a)/abs(b));
          printf("%0.9f\n", abs(a/b));
          printf("\n");
       }
       return 0;
    }
    Reply With Quote  
     

  11. #10  
    Forum Freshman
    Join Date
    Nov 2013
    Posts
    11
    One unit of time equivalent to the value of two weather. What is common, for example, the correlation? And many other statistical parameters.

    The second unit <=> "polynomial.h"
    Code:
    /******************************************************************************
    * A polynomial class is not itself take a stand on its intended purpose.      *
    * For example, noise reduction sliding window is sometimes necessary, etc..   *
    *                                                                             *
    * When the compile code, its use is simple.                                   *
    *                                                                             *
    * for example:                                                                *
    *                                                                             *
    * P = polynomial(time, speed, number of sample points, the polynomial degree) *
    ******************************************************************************/
    
    #ifndef __POLYNOMIAL_H
    #define __POLYNOMIAL_H
    
    class polynomial
    {
       public: /******************************************************************/
    
       areal fx(areal x);
       ~polynomial(void);
       polynomial(areal*, areal*, int, int);
    
       private: /*****************************************************************/
    
       areal *K;
       int p_aste;
    
       double gabs(areal xx);
       void mem00set(void*, int);
       areal getSumX(areal *xx, int);
       areal getSumXY(areal*, areal*, int);
    
       areal fxn(areal*, int, areal x);
       int ratkaise(areal*, areal*, int);
       void swap_rows(areal*, areal*, int);
       void mk_next_pow(areal*, areal*, int);
       void mk__poly(areal*, areal*, int, int);
    
       void copyMatrixLeft(areal*, areal, int, int);
       void copyMatrixDown(areal*, areal, int, int);
    };
    
    polynomial::polynomial(areal *x, areal *y, int n, int a)
    {
       p_aste=a;
       K=new areal[a+1];
       mk__poly(x, y, n, p_aste);
    }
    
    polynomial::~polynomial(void)
    {
       delete[] K;
    }
    
    areal polynomial::fx(areal x)
    {
       return fxn(K, p_aste, x);
    }
    
    double polynomial::gabs(areal xx)
    {
       return abs(xx);
    }
    
    void polynomial::mem00set(void *x, int kpl)
    {
       char *c=(char*)x;
       for (int i=0; i<kpl; i++)
       c[i]=(char)0;
    }
    
    void polynomial::swap_rows(areal *a, areal *b, int n)
    {
       for (int i=0; i<n; i++)
       {
          areal tmp=a[i];
          a[i]=b[i];
          b[i]=tmp;
       }
    }
    
    /******************************************************************************
    * ratkaise (Finnish language) <=> qsolve the return value:                    *
    *    1 <=> group was the solution to the equation                             *
    *    0 <=> equation group there was no solution.                              *
    ******************************************************************************/
    int polynomial::ratkaise(areal *X, areal *f, int n)
    {
       areal k, J;
       areal *max, *mux;
       int i, j, x, M=(int)n+1;
    
       for (i=0; i<n-1; i++)
       {
          max=f+i+i*M;
          for (j=i+1; j<n; j++)
          if (gabs(*(mux=f+i+j*M))>gabs(*max)) max=mux;
    
          if (max!=(mux=f+i+i*M))
          swap_rows(max, mux, M-i);
    
          if (gabs(J=f[i+i*M])<(double)1e-20)
          return 0;  /*There is no solution*/
    
          for (j=i+1; j<n; j++)
          {
             k=-f[i+j*M]/J;
             for (x=i+1; x<M; x++)
             f[x+j*M]=f[x+j*M]+k*f[x+i*M];
          }
       }
    
       for (i=n-1; i>=0; i--)
       {
          k=(areal)f[n+i*M];
          for (j=n-1; j > i; j--)
          k=k-(areal)(X[j]*f[j+i*M]);
    
          if (gabs(J=f[i+i*M])<(double)1e-20)
          return 0; /*There is no solution*/
          else X[i]=k/J; /*is the solution*/
       }
    
       return 1;
    }
    
    areal polynomial::fxn(areal *k, int n, areal x)
    {
       areal sum=k[0];
       areal y=areal(1.0);
       for (int i=1; i<=n; i++)
       {
          y=y*x;
          sum=sum+k[i]*y;
       }
       return sum;
    }
    
    areal polynomial::getSumX(areal *x, int n)
    {
       areal sum=areal(0.0);
       for (int i=0; i<n; i++)
       sum=sum+x[i]; return sum;
    }
    
    areal polynomial::getSumXY(areal *x, areal *y, int n)
    {
       areal sum=areal(0.0);
       for (int i=0; i<n; i++)
       sum=sum+x[i]*y[i]; return sum;
    }
    
    void polynomial::mk_next_pow(areal *x, areal *y, int n)
    {
       for (int i=0; i<n; i++) x[i]=x[i]*y[i];
    }
    
    void polynomial::copyMatrixLeft(areal *L, areal value, int i, int N)
    {
       for (--i; i>=0; i--) {L+=N; *L=value;}
    }
    
    void polynomial::copyMatrixDown(areal *L, areal value, int i, int N)
    {
       for (i+=1; i<N; i++) {L+=N; *L=value;}
    }
    
    void polynomial::mk__poly(areal *X, areal *Y, int kpl, int aste)
    {
       int N=aste+1, i;
       int M=aste+2, j;
       int upa = N*N+N;
    
       areal *x=new areal[kpl];
       areal *L=new areal[upa];
    
       mem00set(x, sizeof(areal)*kpl);
       mem00set(L, sizeof(areal)*upa);
    
       for (i=0; i<kpl; i++) x[i]=(areal)1;
       L[N]=getSumXY(x, Y, (int)kpl);
       L[0]=getSumX(x, kpl);
    
       for (i=1; i<N; i++)
       {
          mk_next_pow(x, X, kpl);
          L[i]=getSumX(x, (int)kpl);
          L[M*i+N]=getSumXY(x, Y, kpl);
          copyMatrixLeft(L+i, L[i], i, N);
       }
    
       for (i=1; i<N; i++)
       {
          j=(int)(i*M+N-0x01);
          mk_next_pow(x, X, kpl);
          L[j]=getSumX(x, (int)kpl);
          copyMatrixDown(L+j, L[j], i, N);
       }
    
       if (!ratkaise(K, L, N))
       {
          /* There is no solution */
          mem00set(K, sizeof(areal)*N);
       }
    
       delete[] L;
       delete[] x;
    }
    
    #endif  /* __POLYNOMIAL_H */
    Code:
    #pragma hdrstop
    
    /*********************************************/
    #include "areal.h" /* ** *** Module 1 *** ** */
    /*********************************************/
    #include "polynomial.h" /* * Module 2 *** ** */
    /*********************************************/
    
    /* ** *** *** ** DEBUG ** *** *** ** DEBUG ** *** *** ** DEBUG ** *** *** ** */
    /* ** *** *** ** DEBUG ** *** *** ** DEBUG ** *** *** ** DEBUG ** *** *** ** */
    /* ** *** *** ** DEBUG ** *** *** ** DEBUG ** *** *** ** DEBUG ** *** *** ** */
    
    /******************************************************************************
    * The following two tables are the least-squares cubic parabola measurement   *
    * equivalence.                                                                *
    ******************************************************************************/
    
    areal Time[24]=
    {
       areal(0),
       areal(1),
       areal(2),
       areal(3),
       areal(4),
       areal(5),
       areal(6),
       areal(7),
       areal(8),
       areal(9),
       areal(10),
       areal(11),
       areal(12),
       areal(13),
       areal(14),
       areal(15),
       areal(16),
       areal(17),
       areal(18),
       areal(19),
       areal(20),
       areal(21),
       areal(22),
       areal(23),
    };
    
    // The temperature of 1 and 2
    areal Temperature[24]=
    {
       areal("2f", 32.1, 24.1),
       areal("2f", 27.6, 21.0),
       areal("2f", 24.7, 18.3),
       areal("2f", 22.0, 13.8),
       areal("2f", 20.0, 15.7),
       areal("2f", 18.5, 10.1),
       areal("2f", 17.1, 13.2),
       areal("2f", 16.2,  9.4),
       areal("2f", 15.6, 11.9),
       areal("2f", 13.5,  9.8),
       areal("2f", 12.4,  4.3),
       areal("2f", 11.9, 14.0),
       areal("2f", 11.2,  8.7),
       areal("2f", 10.2, 14.2),
       areal("2f",  9.0,  2.2),
       areal("2f",  7.7, 10.9),
       areal("2f",  9.4,  5.1),
       areal("2f", 10.2, 15.0),
       areal("2f", 12.4,  9.4),
       areal("2f", 14.9, 12.5),
       areal("2f", 15.5, 16.9),
       areal("2f", 14.3, 14.9),
       areal("2f", 12.5, 18.0),
       areal("2f",  8.8, 20.0),
    };
    
    #pragma argsused
    int main(int kpl, char* asia[])
    {
       polynomial P(Time, Temperature, 24, 3);
    
       for (int i=0; i<24; i++)
       {
          areal x = Time[i];
          areal y = P.fx(x);
          print(x);
          print(y);
          printf("================================================\n");
       }
    
       return 0;
    }
    Reply With Quote  
     

  12. #11  
    Forum Freshman
    Join Date
    Nov 2013
    Posts
    11
    For example, least squares fitting a polynomial 0 ^ 0 is equal to 1, otherwise the algorithm crashes.

    lim (x / x) = 1 when x approaches zero. How can you prove that the limit is not specified the value 0

    Second, there is no reason to break up the least-squares formula of a theoretical reason. Policy dictates of the theory of marginal cases, rather than vice versa.
    Reply With Quote  
     

Similar Threads

  1. Application of algebraic topology.
    By spacecolonization.info in forum Mathematics
    Replies: 9
    Last Post: October 31st, 2013, 02:17 PM
  2. solving algebraic Equations
    By Booms in forum Mathematics
    Replies: 1
    Last Post: April 26th, 2009, 09:07 AM
  3. Nomenclature about algebraic applications
    By doctor_cat in forum Mathematics
    Replies: 2
    Last Post: November 21st, 2008, 09:23 AM
  4. Algebraic Number Theory
    By serpicojr in forum Mathematics
    Replies: 46
    Last Post: August 13th, 2008, 08:47 AM
  5. Algebraic topology (an introduction)
    By JaneBennet in forum Mathematics
    Replies: 21
    Last Post: August 7th, 2008, 08:28 PM
Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •