static int Main() { //the data: //time vector t = new vector(9); t[0] = 1; t[1] = 2; t[2] = 3; t[3] = 4; t[4] = 6; t[5] = 9; t[6] = 10; t[7] = 13; t[8] = 15; //activity vector y = new vector(9); y[0] = 117; y[1] = 100; y[2] = 88; y[3] = 72; y[4] = 53; y[5] = 29.5; y[6] = 25.2; y[7] = 15.2; y[8] = 11.1; //vectors: vector dy = new vector(y.size); vector lny = new vector(y.size); vector dlny = new vector(y.size); var data = new System.IO.StreamWriter("data.txt"); for (int n = 0; n < y.size; n++) { dy[n] = y[n] / 20; //error on y lny[n] = Log(y[n]); dlny[n] = dy[n] / y[n]; //error Ln(y) data.WriteLine($"{t[n]} {y[n]} {dy[n]}"); } //end for data.Close(); //The function: Func <double, double>[] f = new Func <double, double>[] { (x) => 1, (x) => - x }; //making the fit: olsf fit = new olsf(t, lny, dlny, f); //the calculated parameters: vector a = fit.c; //making a new function using the parameters: Func <double, double> F = (x) => Exp(a[0]) * Exp(-a[1] * x); //generating points to fit: var fi = new System.IO.StreamWriter("fit.txt"); for (double n2 = 0; n2 < 20; n2 += 0.05) { fi.WriteLine($"{n2} {F(n2)}"); } //end for fi.Close(); double hl = Log(2) / a[1]; //calculated half life double hlt = 3.6319; double devi = Abs(hlt / hl - 1) * 100; WriteLine("Part A:"); WriteLine("In plotA.svg is a plot of the experimental data and my best calculated fit."); WriteLine($"The moderen value for the half life of 224Ra is 3.6319 days, the value calulated from the fit is given as {Log(2)/a[1]} days. This is a deviation of {devi} %."); return(0); }
static int Main() { //time vector t = new vector(9); t[0] = 1; t[1] = 2; t[2] = 3; t[3] = 4; t[4] = 6; t[5] = 9; t[6] = 10; t[7] = 13; t[8] = 15; //activity vector y = new vector(9); y[0] = 117; y[1] = 100; y[2] = 88; y[3] = 72; y[4] = 53; y[5] = 29.5; y[6] = 25.2; y[7] = 15.2; y[8] = 11.1; //vectors: vector dy = new vector(y.size); vector lny = new vector(y.size); vector dlny = new vector(y.size); var data = new System.IO.StreamWriter("data.txt"); for (int n = 0; n < y.size; n++) { dy[n] = y[n] / 20; lny[n] = Log(y[n]); dlny[n] = dy[n] / y[n]; data.WriteLine($"{t[n]} {y[n]} {dy[n]}"); } //end for data.Close(); Func <double, double>[] f = new Func <double, double>[] { (x) => 1, (x) => - x }; olsf fit = new olsf(t, lny, dlny, f); vector a = fit.c; Func <double, double> F = (x) => Exp(a[0]) * Exp(-a[1] * x); vector dc = fit.dc; Func <double, double> dFp = (x) => Exp(a[0] + dc[0]) * Exp(-(a[1] + dc[1]) * x); Func <double, double> dFm = (x) => Exp(a[0] - dc[0]) * Exp(-(a[1] - dc[1]) * x); var fi = new System.IO.StreamWriter("fit.txt"); for (double n2 = 0; n2 < 20; n2 += 0.05) { fi.WriteLine($"{n2} {F(n2)} {dFp(n2)} {dFm(n2)}"); } //end for fi.Close(); WriteLine("Part C:"); WriteLine("The relevant figure is plotC.svg"); return(0); }
static int Main(string[] args) { // input to vector... var input = new System.IO.StreamReader("time_cyc.txt"); int input_lenght = 0; while (input.ReadLine() != null) { input_lenght++; } input.Close(); input = new System.IO.StreamReader("time_cyc.txt"); vector N = new vector(input_lenght); vector t = new vector(input_lenght); string line; for (int n = 0; n < input_lenght; n++) { line = input.ReadLine(); string[] words = line.Split(' '); N[n] = double.Parse(words[0]); t[n] = double.Parse(words[1]); } //end input to vector... //using oslf to check O(n³)... //function to fit: var ft = new Func <double, double>[] { x => 1, x => x }; //error on time set to 1%: vector dt = new vector(t.size); vector lN = new vector(t.size); vector lt = new vector(t.size); for (int i = 0; i < t.size; i++) { lN[i] = Log(N[i]); lt[i] = Log(t[i]); dt[i] = lt[i] / 100; } //end for //using olsf: olsf fit = new olsf(lN, lt, dt, ft); WriteLine("Part B:"); WriteLine(""); WriteLine("i) Check that the time goes as O(n³)."); WriteLine($"By using my least square fit from Problem 3, i get that the time roughly depends of the matrix size N as t=N^(c), with c={fit.c[1]}."); WriteLine(""); //check that eigenvalue by eigenvalue give same result as cyc //new random matrix: matrix A = randmatrix_sym(4, 4); //using cyc: jac_dia ja = new jac_dia(A); int nr = 0; //number of rotation: matrix V = new matrix(4, 4); vector e1 = jac_dia_red(A, V, 4, ref nr); WriteLine("ii) Implement the value-by-value method"); WriteLine("Check that the eigenvalues becomes the same as using cyclic sweeps."); WriteLine("Random generated symmetic matrix A:"); for (int i = 0; i < A.size1; i++) { for (int k = 0; k < A.size1; k++) { Write($"{A[i,k]} "); } //end for Write("\n"); } //end for Write("\n \n"); WriteLine("Calutaled eigenvalues:"); WriteLine("by cyclic: by value-by-value:"); for (int i = 0; i < ja.e.size; i++) { WriteLine($"{ja.e[i]} {e1[i]}"); } //end for WriteLine(""); WriteLine("iii) and iv) Compare speed."); WriteLine("In plot_time.svg the time used by the cyclic sweeps method to calculate alle the eigenvalues, is compared to the time used by the value-by-value method to calculate the first and all eigenvalue(s)."); WriteLine("It is faster to only calculate the first value by the value-by-value method then using cyclic sweeps. But cyclic sweeps is significant the calculated all eigenvalues by the value-by-value method."); WriteLine("In plot_rotation.svg the number of rotationes is compared."); WriteLine(""); //largest eigenvalue matrix V2 = new matrix(4, 4); int nr2 = 0; vector eh = jac_dia_high_e(A, V2, 3, ref nr2); WriteLine($"v) Largest eigenvalue."); WriteLine($"By changing the theta angle from Atan2(2*Apq, Aq-Ap) to Atan2(-2*Apq, App-Aqq) the larges eigenvlaue can be calculated."); WriteLine($"For vector A the value becomes: {eh[0]} the same as found by cyclic sweeps."); return(0); } // end Main
static int Main() { //the data: //time vector t = new vector(9); t[0] = 1; t[1] = 2; t[2] = 3; t[3] = 4; t[4] = 6; t[5] = 9; t[6] = 10; t[7] = 13; t[8] = 15; //activity vector y = new vector(9); y[0] = 117; y[1] = 100; y[2] = 88; y[3] = 72; y[4] = 53; y[5] = 29.5; y[6] = 25.2; y[7] = 15.2; y[8] = 11.1; //vectors: vector dy = new vector(y.size); vector lny = new vector(y.size); vector dlny = new vector(y.size); //var data=new System.IO.StreamWriter("data.txt"); for (int n = 0; n < y.size; n++) { dy[n] = y[n] / 20; //error on y lny[n] = Log(y[n]); dlny[n] = dy[n] / y[n]; //error Ln(y) //data.WriteLine($"{t[n]} {y[n]} {dy[n]}"); } //end for //data.Close(); //The function: Func <double, double>[] f = new Func <double, double>[] { (x) => 1, (x) => - x }; //making the fit: olsf fit = new olsf(t, lny, dlny, f); //the calculated parameters: vector a = fit.c; //making a new function using the parameters: //Func<double, double> F= (x) => Exp(a[0])*Exp(-a[1]*x); //generating points to fit: /* var fi=new System.IO.StreamWriter("fit.txt"); * for(double n2=0; n2<20; n2+=0.05){ * fi.WriteLine($"{n2} {F(n2)}"); * }//end for * fi.Close(); */ double hl = Log(2) / a[1]; //calculated half life WriteLine("Part B:"); //WriteLine("In plotA.svg is a plot of the experimental data and my best calculated fit."); //WriteLine($"The moderen value for the half life of 224Ra is 3.6319 days, the value calulated from the fit is given as {Log(2)/a[1]}. This is a deviation of {devi} %."); matrix sigma = fit.Sigma; WriteLine("The coveriance matrix to the fit displayed in plotA.svg takes the form:"); WriteLine($"{sigma[0,0]} {sigma[0,1]}"); WriteLine($"{sigma[1,0]} {sigma[1,1]}"); Write("\n"); vector dc = fit.dc; WriteLine($"The calculated half life (with uncertainty is {hl} +/- {dc[1]/a[1]/a[1]*Log(2)} days. The moderen value for the half life of 224Ra is 3.6319 days, this means the the morderen value is not within estimated uncertainty."); return(0); }