正文

解决条纹级次的实验程序2007-04-16 22:11:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/soliddream/24942.html

分享到:

//---------------main------------------------  #include <vector>  #include <iostream>  #include "spline3.h"  #include <fstream>  #include "math.h"   #include "FringeOrder.h"  using namespace std;    int main()  { int n,m,i,j;    double u,s;    static double x[512],y[512],dy[512],ddy[512];   // static double t[36],z[36],dz[36],ddz[36];    Spline3 info;    for (i=0;i<512;i++)    {         x[i]=i;        y[i]=sin(5*3.1415926*x[i]/512);        info.readinto(x[i],y[i],0,0);    }    //for (i=0;i<=35;i++) t[i]=(0.5+i)*6.2831852/36.0;    n=512;    //m=36;    info.spl3( );        ofstream outfile( "data.txt" );    if ( ! outfile ) {            cerr << "error: unable to open output file!\n";            return -1;     }    outfile<<info;    outfile.close();    cout<<info<<'\n';                info.erase();        ifstream infile( "data.txt" );    if ( ! infile ) {            cerr << "error: unable to open input file!\n";            return -2;     }    double array[4];    i=0;    double data;    while(!infile.eof())    {        int j=i%4;                while(infile&&(data=infile.get())!=' ');                infile>>array[j];        if(j==3) info.readinto(array[0],array[1],array[2],array[3]);                ++i;    }    cout<<info;    cout<<endl;    vector<double>temp;    vector<int>number;    info.order(temp,number);    FringeOrder *pinfo=new FringeOrder(temp,number);    cout<<*pinfo;  } // Spline3.h: interface for the Spline3 class.////////////////////////////////////////////////////////////////////////#if !defined(AFX_SPLINE3_H__5684D9F7_AF78_44BA_8295_29CC93A11696__INCLUDED_)#define AFX_SPLINE3_H__5684D9F7_AF78_44BA_8295_29CC93A11696__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000  #include <vector>  #include <iostream>  #include <fstream>   using namespace std;class Spline3  {friend ostream& operator<< (ostream& stream, const Spline3& temp);public:    Spline3();    virtual ~Spline3();    void erase();    void readinto(double ,double ,double ,double);    double spl3( );    void order(vector<double>&temp,vector<int>&number);private:    int n;    vector<double> x;    vector<double> y;    vector<double> dy;    vector<double> ddy;};#endif // !defined(AFX_SPLINE3_H__5684D9F7_AF78_44BA_8295_29CC93A11696__INCLUDED_)// Spline3.cpp: implementation of the Spline3 class.////////////////////////////////////////////////////////////////////////#include "Spline3.h"#include "math.h"#include <iostream>using namespace std;//////////////////////////////////////////////////////////////////////// Construction/Destruction//////////////////////////////////////////////////////////////////////Spline3::Spline3(){    n=0;}void Spline3::readinto(double Tx,double Ty,double Tdy,double Tddy){    x.push_back(Tx);    y.push_back(Ty);    dy.push_back(Tdy);    ddy.push_back(Tddy);    n++;}ostream& operator<< (ostream& stream, const Spline3& temp){    for(int i=0;i<temp.n;i++)        stream<<' '<<temp.x[i]<<' '<<temp.y[i]<<' '<<temp.dy[i]<<' '<<temp.ddy[i]<<'\n';    return stream;}void Spline3::erase(){    x.erase(x.begin(),x.end());    y.erase(y.begin(),y.end());    dy.erase(dy.begin(),dy.end());    ddy.erase(ddy.begin(),ddy.end());    n=0;}void Spline3::order(vector<double>&temp,vector<int>&num){    for(int i=1,int j=0;i<n;i++)    {                if(dy[i-1]<=0&&dy[i]>=0&&ddy[i]>0&&y[i]<-0.9)         {            temp.push_back((-dy[i-1])<dy[i]?x[i-1]:x[i]);            if(i<n/2) j++;            else j--;            num.push_back(j);        }    }}                    Spline3::~Spline3(){}double Spline3::spl3( ){    int i,j;    vector<double>Tx,Ty,Tdy,Tddy;        Tx=x;Ty=y;Tdy=dy;Tddy=ddy;    double h0,y0,h1,y1,alpha,beta,u,g;    double* s=new double[n];    h0=Tx[n-1]-Tx[n-2];    y0=Ty[n-1]-Ty[n-2];    Tdy[0]=0.0; Tddy[0]=0.0; Tddy[n-1]=0.0;    s[0]=1.0; s[n-1]=1.0;    for (j=1;j<=n-1;j++)      { h1=h0; y1=y0;        h0=Tx[j]-Tx[j-1];        y0=Ty[j]-Ty[j-1];        alpha=h1/(h1+h0);        beta=3.0*((1.0-alpha)*y1/h1+alpha*y0/h0);        if (j<n-1)          { u=2.0+(1.0-alpha)*Tdy[j-1];            Tdy[j]=-alpha/u;            s[j]=(alpha-1.0)*s[j-1]/u;            Tddy[j]=(beta-(1.0-alpha)*Tddy[j-1])/u;          }      }    for (j=n-2;j>=1;j--)      { s[j]=Tdy[j]*s[j+1]+s[j];        Tddy[j]=Tdy[j]*Tddy[j+1]+Tddy[j];      }    Tdy[n-2]=(beta-alpha*Tddy[1]-(1.0-alpha)*Tddy[n-2])/            (alpha*s[1]+(1.0-alpha)*s[n-2]+2.0);    for (j=2;j<=n-1;j++)        Tdy[j-2]=s[j-1]*Tdy[n-2]+Tddy[j-1];    Tdy[n-1]=Tdy[0];    for (j=0;j<=n-2;j++) s[j]=Tx[j+1]-Tx[j];    for (j=0;j<=n-2;j++)      { h1=s[j]*s[j];        Tddy[j]=6.0*(Ty[j+1]-Ty[j])/h1-2.0*(2.0*Tdy[j]+Tdy[j+1])/s[j];      }    h1=s[n-2]*s[n-2];    Tddy[n-1]=6.*(Ty[n-2]-Ty[n-1])/h1+2.*(2.*Tdy[n-1]+Tdy[n-2])/s[n-2];    g=0.0;    for (i=0;i<=n-2;i++)      { h1=0.5*s[i]*(Ty[i]+Ty[i+1]);        h1=h1-s[i]*s[i]*s[i]*(Tddy[i]+Tddy[i+1])/24.0;        g=g+h1;      }    x=Tx;y=Ty;dy=Tdy;ddy=Tddy;    delete []s;    return(g);} #if !defined(AFX_FRINGEORDER_H__46F611FD_CF6F_4558_A06B_F7EEEEAA86B6__INCLUDED_)#define AFX_FRINGEORDER_H__46F611FD_CF6F_4558_A06B_F7EEEEAA86B6__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000#include<vector>#include<iostream>using namespace std;class FringeOrder  {    friend ostream& operator<< (ostream& stream, const FringeOrder& temp);public:    FringeOrder();    FringeOrder(vector<double>temp,vector<int>number);    virtual ~FringeOrder();private:    vector<double>x;    vector<int>num;};#endif // !defined(AFX_FRINGEORDER_H__46F611FD_CF6F_4558_A06B_F7EEEEAA86B6__INCLUDED_)// FringeOrder.cpp: implementation of the FringeOrder class.////////////////////////////////////////////////////////////////////////#include "FringeOrder.h"//////////////////////////////////////////////////////////////////////// Construction/Destruction//////////////////////////////////////////////////////////////////////FringeOrder::FringeOrder(){}FringeOrder::FringeOrder(vector<double>temp,vector<int>number){    for(int i=0;i<number.size();i++)    {        num.push_back(number[i]);        x.push_back(temp[i]);    }    }FringeOrder::~FringeOrder(){}ostream& operator<< (ostream& stream, const FringeOrder& temp){    for(int i=0;i<temp.num.size();i++)        stream<<"Fringe Order : "<<temp.num[i]<<'\t'<<"The position of x : "<<temp.x[i]<<'\n';    return stream;} 光弹方面条纹级次问题,拿出来与大家一起分享,欢迎交流,一些初步解释过几天再发欢迎大家指正我做的这个程序的不足之处。

阅读(2595) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册