예제 #1
0
파일: main.cs 프로젝트: HeleneHJ/PPNM
static void Main(){

int n=5, N=200;
double[] x = new double[n];
double[] y = new double[n];

int i;
for (i=1; i<n; i++){
	x[i]=2*PI*i/(n-1);
	y[i]=Sin(x[i]);
	WriteLine("{0:g6} {1:g6}",x[i],y[i]);
	}

Write("\n\n");

var qs = new qspline(x,y);
double z, step=(x[n-1]-x[0])/(N-1);
for (z=x[0], i=0; i<N; z=x[0]+(++i)*step){
	WriteLine($"{z} {Sin(z)} {qs.eval(z)}");
	}
Write("\n\n");
for (z=x[0], i=0; i<N; z=x[0]+(++i)*step){
	WriteLine($"{z} {Cos(z)} {qs.deriv(z)}");
	}
Write("\n\n");
for (z=x[0], i=0; i<N; z=x[0]+(++i)*step){
	WriteLine($"{z} {1-Cos(z)} {qs.integ(z)}");
	}

}//Main
예제 #2
0
파일: MainB.cs 프로젝트: joha3332/PPNM
    static int Main(string[] args)
    {
        if (args.Length < 3)
        {
            Console.Error.WriteLine("too few arguments");
            return(1);
        }
        string       infile     = args[0];
        string       outfile1   = args[1];
        string       outfile2   = args[2];
        string       outfile3   = args[3];
        StreamReader instream   = new StreamReader(infile);
        StreamWriter outstream1 = new StreamWriter(outfile1, append: false);
        StreamWriter outstream2 = new StreamWriter(outfile2, append: false);
        StreamWriter outstream3 = new StreamWriter(outfile3, append: false);

        //Importing the data into vectors
        List <double> xlist = new List <double>();
        List <double> ylist = new List <double>();

        do
        {
            string line = instream.ReadLine();
            if (line == null)
            {
                break;
            }
            string[] values = line.Split(' ', '\t');

            xlist.Add(Double.Parse(values[0]));
            ylist.Add(Double.Parse(values[1]));
        } while (true);

        int    n = xlist.Count;
        vector x = new vector(n);
        vector y = new vector(n);

        for (int i = 0; i <= (n - 1); i++)
        {
            x[i] = xlist[i];
            y[i] = ylist[i];
        }

        qspline s = new qspline(x, y);
        // Evaluating the spline
        int N = 999;

        for (int i = 0; i <= N; i++)
        {
            double z  = (x[n - 1] - x[0]) / N * i + x[0];
            double yz = s.eval(z);
            outstream1.WriteLine($"{z} \t {yz}");
        }

        // Evaluating the derivetives of the spline
        for (int i = 0; i <= N; i++)
        {
            double z       = (x[n - 1] - x[0]) / N * i + x[0];
            double slope_z = s.derivative(z);
            outstream2.WriteLine($"{z} \t {slope_z}");
        }


        // Evaluating the derivetives of the spline
        for (int i = 0; i <= N; i++)
        {
            double z      = (x[n - 1] - x[0]) / N * i + x[0];
            double area_z = s.integral(z);
            outstream3.WriteLine($"{z} \t {area_z}");
        }

        outstream1.Close();
        outstream2.Close();
        outstream3.Close();
        instream.Close();

        return(0);
    }