-
June 16th, 2010, 04:27 PM
#1
C++ Realisation of The Full Squares Method
Hello, Gurus. Please, help me. I have written C++ Realisation of The Full Squares Method in Visual Studio 2010. My application has no compilation errors. But the idea of this method is approximation of experimental data by a parabolic function. Despite this, my program gives me no approximation!!! The graphic made by the results of approximation is particullary different from the experimental data graphic. Please, tell me, what can I do? Where is the error? Here is the text of my program:
__________________________________________________________________________
#include<stdio.h>
#include<math.h>
#include<conio.h>
#include <iostream>
#define n 3
#define m 4
using namespace std;
void main()
{
double x[20], y[20], dy[20];
double Sx, Sy, Sx2, Sx3, Sx4, Syx, Syx2, S;
Sx=0;
Syx=0;
Sy=0;
Syx2=0;
Sx2=0;
Sx3=0;
Sx4=0;
double z[20]={2.05,2.3,2.27,2.31,2.52,2.63,2.58,2.54,2.5,2.62,2.1,2.28,2.,1.62,1.44,1.04,0.84,0.5,0.13,-0.13};
int N1=14;
int N=20;
for(int i=0;i<20;i++)
{
x[i]=(i-1)*0.1;
y[i]=z[i]+N1*0.1;
Sx=Sx+x[i];
Sx2=Sx2+pow(x[i],2);
Sx3=Sx3+pow(x[i],3);
Sx4=Sx4+pow(x[i],4);
Sy=Sy+y[i];
Syx=Syx+y[i]*x[i];
Syx2=Sx2+y[i]*pow(x[i],2);
}
for(int i=0;i<20;i++)
{
printf("%le\t %le\n",x[i],y[i]);
}
{double a[3][4]={{Sx4,Sx3,Sx2,Syx2},{Sx3,Sx2,Sx,Syx},{Sx2,Sx,N,Sy}};
int ii,j,k;
double r[3],c,s;
printf("\n isxodnaya matrica: \n");
for(ii=0;ii<n;ii++)
{for(j=0;j<m;j++)
printf("%f\t",a[ii][j]);
printf("\n");
}
printf("\n____________________________\n");
for(ii=0;ii<n;ii++)
{c=a[ii][ii];
for(j=0;j<m;j++)
a[ii][j]=a[ii][j]/c;
if(ii!=n-1)
{
for(k=ii+1;k<n;k++)
for(j=0;j<m;j++)a[k][j]=a[k][j]-a[ii][j]*a[k][ii];
}
}
printf("\n 2-naya matrica: \n");
for(ii=0;ii<n;ii++)
{for(j=0;j<m;j++)
printf("%f\t",a[ii][j]);
printf("\n");
}
printf("n=%d\tm=%d\t",n,m);
for(ii=0;ii<n;ii++)r[ii]=0;
//x[n-1]=a[n-1][n];
for(ii=n-1;ii>=0;ii--)
{s=0;
for(j=n-1;j>=0;j--)s=s+a[ii][j]*r[j];
r[ii]=a[ii][m-1]-s;
}
printf("\n Korni: \n");
for(ii=0;ii<n;ii++)
printf("\n r[%d]=%f",ii,r[ii]);
printf("\n");
printf("\n proverka: \n");
for(ii=0;ii<n;ii++)
{s=0;for(j=0;j<n;j++)s+=a[ii][j]*r[j];
printf("\n %d-e: %f=%f\n",ii,s,a[ii][m-1]);
printf("\n");
}
double Y[20];
for(int i=0;i<20;i++)
{
x[i]=(i-1)*0.1;
Y[i]=r[0]*pow(x[i],2)+r[1]*x[i]+r[2];
}
S=0;
for(int i=0;i<20;i++)
{
dy[i]=y[i]-Y[i];
S=S+pow(dy[i],2);
}
for(int i=0;i<20;i++)
{
printf("%f\t %f\n",x[i],Y[i]);
}
printf("\n\nS=%f\t",S);
_getch();
}
}
_____________________________________________________________________________
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|