public static object GetInterpolatedValues(object[] X, object[] Y, object OnlyReturnBlanks) { bool flag = Utils.GetOptionalParameter(OnlyReturnBlanks, false); SortedDictionary <double, double> xy = new SortedDictionary <double, double>(); for (int i = 0; i < X.Length; ++i) { if (i < Y.Length && !(Y[i] is ExcelMissing || Y[i] is ExcelEmpty || Y[i] is ExcelError || Y[i] is string)) { xy.Add((double)X[i], (double)Y[i]); } } CubicSplineInterpolation csi = new CubicSplineInterpolation(xy.Keys.ToArray(), xy.Values.ToArray()); double[] values = new double[X.Length]; for (int i = 0; i < X.Length; ++i) { if (!flag || !xy.ContainsKey((double)X[i])) { values[i] = csi.Interpolate((double)X[i]); } } return(values.ToRange()); }
/// <summary> /// Returns a list of 3d POINTS. Uses cubic spline to interpolate. /// </summary> /// <param name="NumberOfPoints"></param> /// <returns></returns> public List <Point3D> Get3DPoints(int NumberOfPoints) { List <Point3D> interpolatedpoints = new List <Point3D>(); CubicSplineInterpolation spline = new CubicSplineInterpolation(); List <double> xcoors = new List <double>(); List <double> zcoors = new List <double>(); for (int i = 0; i < _xsec.Points.Count(); i++) { xcoors.Add(_xsec.Points[i].X); zcoors.Add(_xsec.Points[i].Z); } spline.Initialize(xcoors, zcoors); double xOffset = _xsec.LowestPoint.X; double dx = (xcoors.Last() - xcoors.First()) / NumberOfPoints; for (int i = 0; i < NumberOfPoints; i++) { double x = xcoors.First() + i * dx; double z = spline.Interpolate(x); interpolatedpoints.Add(new Point3D(MidStreamLocation.X - UnityVector.Y * (x - xOffset), MidStreamLocation.Y + UnityVector.X * (x - xOffset), z)); } return(interpolatedpoints); }
public void NaturalFitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError) { IInterpolation interpolation = new CubicSplineInterpolation(_t, _x); Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); var actual = interpolation.DifferentiateAll(t); Assert.AreEqual(x, actual.Item1, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t); }
public void FixedSecondDerivativeFitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError) { IInterpolation interpolation = new CubicSplineInterpolation(_t, _x, SplineBoundaryCondition.SecondDerivative, -5.0, SplineBoundaryCondition.SecondDerivative, -1.0); Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); var actual = interpolation.DifferentiateAll(t); Assert.AreEqual(x, actual.Item1, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t); }
public void FixedFirstDerivativeFitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError) { IInterpolation interpolation = new CubicSplineInterpolation(_t, _x, SplineBoundaryCondition.FirstDerivative, 1.0, SplineBoundaryCondition.FirstDerivative, -1.0); Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); double interpolatedValue; double secondDerivative; interpolation.Differentiate(t, out interpolatedValue, out secondDerivative); Assert.AreEqual(x, interpolatedValue, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t); }
public void NaturalSupportsLinearCase(int samples) { double[] x, y, xtest, ytest; LinearInterpolationCase.Build(out x, out y, out xtest, out ytest, samples); IInterpolation interpolation = new CubicSplineInterpolation(x, y); for (int i = 0; i < xtest.Length; i++) { Assert.AreEqual(ytest[i], interpolation.Interpolate(xtest[i]), 1e-15, "Linear with {0} samples, sample {1}", samples, i); } }
public void NaturalFitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError) { IInterpolation interpolation = new CubicSplineInterpolation(_t, _x); Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); double interpolatedValue; double secondDerivative; interpolation.Differentiate(t, out interpolatedValue, out secondDerivative); Assert.AreEqual(x, interpolatedValue, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t); }
public void FixedSecondDerivativeFitsAtSamplePoints() { IInterpolation interpolation = new CubicSplineInterpolation(_t, _x, SplineBoundaryCondition.SecondDerivative, -5.0, SplineBoundaryCondition.SecondDerivative, -1.0); for (int i = 0; i < _x.Length; i++) { Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i); var actual = interpolation.DifferentiateAll(_t[i]); Assert.AreEqual(_x[i], actual.Item1, "B Exact Point " + i); } }
public void NaturalFitsAtSamplePoints() { IInterpolation interpolation = new CubicSplineInterpolation(_t, _x); for (int i = 0; i < _x.Length; i++) { Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i); var actual = interpolation.DifferentiateAll(_t[i]); Assert.AreEqual(_x[i], actual.Item1, "B Exact Point " + i); } }
public void NaturalFitsAtSamplePoints() { IInterpolation interpolation = new CubicSplineInterpolation(_t, _x); for (int i = 0; i < _x.Length; i++) { Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i); double interpolatedValue; double secondDerivative; interpolation.Differentiate(_t[i], out interpolatedValue, out secondDerivative); Assert.AreEqual(_x[i], interpolatedValue, "B Exact Point " + i); } }
public void FixedSecondDerivativeFitsAtSamplePoints() { IInterpolation interpolation = new CubicSplineInterpolation(_t, _x, SplineBoundaryCondition.SecondDerivative, -5.0, SplineBoundaryCondition.SecondDerivative, -1.0); for (int i = 0; i < _x.Length; i++) { Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i); double interpolatedValue; double secondDerivative; interpolation.Differentiate(_t[i], out interpolatedValue, out secondDerivative); Assert.AreEqual(_x[i], interpolatedValue, "B Exact Point " + i); } }
public void FixedFirstDerivativeFitsAtSamplePoints() { IInterpolation interpolation = new CubicSplineInterpolation(_t, _x, SplineBoundaryCondition.FirstDerivative, 1.0, SplineBoundaryCondition.FirstDerivative, -1.0); for (int i = 0; i < _x.Length; i++) { Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i); double interpolatedValue; double secondDerivative; interpolation.Differentiate(_t[i], out interpolatedValue, out secondDerivative); Assert.AreEqual(_x[i], interpolatedValue, "B Exact Point " + i); } }
public void NaturalFitsAtSamplePoints() { IInterpolation interpolation = new CubicSplineInterpolation(_t, _x); for (int i = 0; i < _x.Length; i++) { Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i); double interpolatedValue; double secondDerivative; interpolation.Differentiate(_t[i], out interpolatedValue, out secondDerivative); Assert.AreEqual(_x[i], interpolatedValue, "B Exact Point " + i); } }
public void FixedFirstDerivativeFitsAtArbitraryPointsWithMaple( [Values(-2.4, -0.9, -0.5, -0.1, 0.1, 0.4, 1.2, 10.0, -10.0)] double t, [Values(1.12, 1.8243928571428571428, .54910714285714285715, -.78903571428571428572, -1.1304642857142857143, -1.1040000000000000000, .4148571428571428571, -608.14285714285714286, 1330.1428571428571429)] double x, [Values(1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-12, 1e-12)] double maxAbsoluteError) { IInterpolation interpolation = new CubicSplineInterpolation(_t, _x, SplineBoundaryCondition.FirstDerivative, 1.0, SplineBoundaryCondition.FirstDerivative, -1.0); Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); double interpolatedValue; double secondDerivative; interpolation.Differentiate(t, out interpolatedValue, out secondDerivative); Assert.AreEqual(x, interpolatedValue, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t); }
public void NaturalFitsAtArbitraryPointsWithMaple( [Values(-2.4, -0.9, -0.5, -0.1, 0.1, 0.4, 1.2, 10.0, -10.0)] double t, [Values(.144, 1.7906428571428571429, .47321428571428571431, -.80992857142857142857, -1.1089285714285714286, -1.0285714285714285714, .30285714285714285716, 189, 677)] double x, [Values(1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-12)] double maxAbsoluteError) { IInterpolation interpolation = new CubicSplineInterpolation(_t, _x); Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); double interpolatedValue; double secondDerivative; interpolation.Differentiate(t, out interpolatedValue, out secondDerivative); Assert.AreEqual(x, interpolatedValue, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t); }
/// <summary> /// Interpolation of the interface points onto the equidistant Fourier points /// </summary> protected void InterpolateOntoFourierPoints(MultidimensionalArray interP, double[] samplP) { int numP = interP.Lengths[0]; // set interpolation data double[] independentVal = new double[numP + 2]; double[] dependentVal = new double[numP + 2]; for (int sp = 1; sp <= numP; sp++) { independentVal[sp] = interP[sp - 1, 0]; dependentVal[sp] = interP[sp - 1, 1]; } // extend the interpolation data for sample points at the boundary of the domain independentVal[0] = interP[numP - 1, 0] - DomainSize; dependentVal[0] = interP[numP - 1, 1]; independentVal[numP + 1] = interP[0, 0] + DomainSize; dependentVal[numP + 1] = interP[0, 1]; switch (this.InterpolationType) { case Interpolationtype.LinearSplineInterpolation: LinearSplineInterpolation LinSpline = new LinearSplineInterpolation(); LinSpline.Initialize(independentVal, dependentVal); for (int sp = 0; sp < numFp; sp++) { samplP[sp] = LinSpline.Interpolate(FourierP[sp]); //invDFT_coeff[sp] = (Complex)samplP[sp]; } break; case Interpolationtype.CubicSplineInterpolation: CubicSplineInterpolation CubSpline = new CubicSplineInterpolation(); CubSpline.Initialize(independentVal, dependentVal); for (int sp = 0; sp < numFp; sp++) { samplP[sp] = CubSpline.Interpolate(FourierP[sp]); //invDFT_coeff[sp] = (Complex)samplP[sp]; } break; default: throw new NotImplementedException(); } }
public void FixedFirstDerivativeFitsAtArbitraryPointsWithMaple( [Values(-2.4, -0.9, -0.5, -0.1, 0.1, 0.4, 1.2, 10.0, -10.0)] double t, [Values(1.12, 1.8243928571428571428, .54910714285714285715, -.78903571428571428572, -1.1304642857142857143, -1.1040000000000000000, .4148571428571428571, -608.14285714285714286, 1330.1428571428571429)] double x, [Values(1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-12, 1e-12)] double maxAbsoluteError) { IInterpolation interpolation = new CubicSplineInterpolation(_t, _x, SplineBoundaryCondition.FirstDerivative, 1.0, SplineBoundaryCondition.FirstDerivative, -1.0); Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); double interpolatedValue; double secondDerivative; interpolation.Differentiate(t, out interpolatedValue, out secondDerivative); Assert.AreEqual(x, interpolatedValue, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t); }
public void FixedSecondDerivativeFitsAtArbitraryPointsWithMaple( [Values(-2.4, -0.9, -0.5, -0.1, 0.1, 0.4, 1.2, 10.0, -10.0)] double t, [Values(-.8999999999999999993, 1.7590357142857142857, .41517857142857142854, -.82010714285714285714, -1.1026071428571428572, -1.0211428571428571429, .31771428571428571421, 39, -37)] double x, [Values(1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-13, 1e-12)] double maxAbsoluteError) { IInterpolation interpolation = new CubicSplineInterpolation(_t, _x, SplineBoundaryCondition.SecondDerivative, -5.0, SplineBoundaryCondition.SecondDerivative, -1.0); Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); double interpolatedValue; double secondDerivative; interpolation.Differentiate(t, out interpolatedValue, out secondDerivative); Assert.AreEqual(x, interpolatedValue, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t); }
public void NaturalFitsAtArbitraryPointsWithMaple( [Values(-2.4, -0.9, -0.5, -0.1, 0.1, 0.4, 1.2, 10.0, -10.0)] double t, [Values(.144, 1.7906428571428571429, .47321428571428571431, -.80992857142857142857, -1.1089285714285714286, -1.0285714285714285714, .30285714285714285716, 189, 677)] double x, [Values(1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-12)] double maxAbsoluteError) { IInterpolation interpolation = new CubicSplineInterpolation(_t, _x); Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); double interpolatedValue; double secondDerivative; interpolation.Differentiate(t, out interpolatedValue, out secondDerivative); Assert.AreEqual(x, interpolatedValue, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t); }
/// <summary> /// Interpolation of no equidistant sample point onto equidistant Fourier points /// </summary> public static void InterpolateOntoFourierPoints(MultidimensionalArray samplP, double DomainSize, double[] samplFp) { int numSp = samplP.Lengths[0]; // set interpolation data (delete multiple independent values) ArrayList independentList = new ArrayList(); ArrayList dependentList = new ArrayList(); for (int sp = 0; sp < numSp; sp++) { if (independentList.Contains(samplP[sp, 0]) == false) { independentList.Add(samplP[sp, 0]); dependentList.Add(samplP[sp, 1]); } } // extend the interpolation data for sample points at the boundary of the domain independentList.Insert(0, samplP[numSp - 1, 0] - DomainSize); independentList.Insert(independentList.Count, samplP[0, 0] + DomainSize); dependentList.Insert(0, samplP[numSp - 1, 1]); dependentList.Insert(dependentList.Count, samplP[0, 1]); double[] independentVal = (double[])independentList.ToArray(typeof(double)); double[] dependentVal = (double[])dependentList.ToArray(typeof(double)); // set Fourier points int numSFp = samplFp.Length; double[] FourierP = new double[numSFp]; for (int i = 0; i < numSFp; i++) { FourierP[i] = (DomainSize / numSFp) * i; } switch (InterpolationType) { case Interpolationtype.LinearSplineInterpolation: LinearSplineInterpolation LinSpline = new LinearSplineInterpolation(); LinSpline.Initialize(independentVal, dependentVal); for (int Fp = 0; Fp < numSFp; Fp++) { samplFp[Fp] = LinSpline.Interpolate(FourierP[Fp]); } break; case Interpolationtype.CubicSplineInterpolation: CubicSplineInterpolation CubSpline = new CubicSplineInterpolation(); CubSpline.Initialize(independentVal, dependentVal); for (int Fp = 0; Fp < numSFp; Fp++) { samplFp[Fp] = CubSpline.Interpolate(FourierP[Fp]); } break; default: throw new NotImplementedException(); } }
static void Main(string[] args) { char[] replace = { ' ', ',', '\t', '\n', Convert.ToChar(10), Convert.ToChar(13) }; char[] replace2SiO2 = { ' ', '\t', '\n', Convert.ToChar(10), Convert.ToChar(13) }; //rn fn double ChangeX, ChangeY1, ChangeY2; #region 1.1 Dat 파일 읽기 //700nm 미포함 string[] Dat_sioDat = File.ReadAllLines("SiO2 1000nm_on_Si.dat", Encoding.Default); List <sio2_2nm_on_si_dat> Dat_wavelen = new List <sio2_2nm_on_si_dat>(); StreamReader sio2_2nm_text = new StreamReader(new FileStream("SiO2 1000nm_on_Si.dat", FileMode.Open)); foreach (var line in Dat_sioDat) { string[] splietData = line.Split(replace, StringSplitOptions.RemoveEmptyEntries); Dat_wavelen.Add(new sio2_2nm_on_si_dat { wavelength = splietData[0], AOI = splietData[1], Alpha = splietData[2], Beta = splietData[3], }); } List <double> List_dat_wave = new List <double>(); List <double> List_dat_aoi = new List <double>(); List <double> List_dat_alpha = new List <double>(); List <double> List_dat_beta = new List <double>(); double waveToDoubeWabe; for (int i = 1; i < Dat_sioDat.Length; i++) { waveToDoubeWabe = Convert.ToDouble(Dat_wavelen[i].wavelength); if (waveToDoubeWabe > 350 && waveToDoubeWabe < 980) { List_dat_wave.Add(waveToDoubeWabe); List_dat_aoi.Add(Convert.ToDouble(Dat_wavelen[i].AOI)); List_dat_alpha.Add(Convert.ToDouble(Dat_wavelen[i].Alpha)); List_dat_beta.Add(Convert.ToDouble(Dat_wavelen[i].Beta)); } } double[] Dat_double_wavelength = List_dat_wave.ToArray(); double[] Dat_double_AOI = List_dat_aoi.ToArray(); double[] Dat_double_Alpha = List_dat_alpha.ToArray(); double[] Dat_double_Beta = List_dat_beta.ToArray(); #endregion #region 1.2 Dat 파일 읽기 //700nm 포함 List <double> List_dat_wave_700 = new List <double>(); List <double> List_dat_aoi_700 = new List <double>(); List <double> List_dat_alpha_700 = new List <double>(); List <double> List_dat_beta_700 = new List <double>(); double waveToDoubeWabe_700; waveToDoubeWabe_700 = Convert.ToDouble(Dat_wavelen[1].wavelength); //0~399 총400개 400번을 700을 넣어주기 List_dat_wave_700 = List_dat_wave; List_dat_wave_700.Add(700.0); double[] Sort_Dat_Wave = List_dat_wave_700.ToArray(); Array.Sort(Sort_Dat_Wave); Console.WriteLine("12"); //새 파일 만들기 //StreamWriter Dat_700nm= new StreamWriter(new FileStream("SiO2 1000nm_on_Si(700nm).dat", FileMode.Create)); //List<sio2_2nm_on_si_dat> List_Dat_700 = new List<sio2_2nm_on_si_dat>(); //Dat_700nm.WriteLine("wavelength(nm)\tAOI\tAlpha\tBeta"); //for (int i = 0; i < Dat_double_wavelength.Length+1; i++) //{ // List_Dat_700.Add(new sio2_2nm_on_si_dat // { // wavelength = List_dat_wave[i], // }) ; //} sio2_2nm_text.Close(); #endregion #region 2.SiN 읽기--------------------------------------- string[] siLines = File.ReadAllLines("SiN.txt", Encoding.Default); List <SiData> ReadData = new List <SiData>(); StreamWriter newdatfile = new StreamWriter(new FileStream("SIN.txt", FileMode.Open)); foreach (var line in siLines) { string[] splitData = line.Split(replace, StringSplitOptions.RemoveEmptyEntries); if (ReadData.Count <= 1) { ReadData.Add(new SiData()); } if (ReadData.Count > 1) { ReadData.Add( new SiData { NM = splitData[0], N = splitData[1], K = splitData[2] }); } } List <double> List_SIN_NM = new List <double>(); List <double> List_SIN_N = new List <double>(); List <double> List_SIN_K = new List <double>(); for (int i = 3; i < siLines.Length; i++) { ChangeX = double.Parse(ReadData[i].NM); ChangeY1 = double.Parse(ReadData[i].N); ChangeY2 = double.Parse(ReadData[i].K); List_SIN_NM.Add(ChangeX); List_SIN_N.Add(ChangeY1); List_SIN_K.Add(ChangeY2); } double[] Sin_nm = List_SIN_NM.ToArray(); double[] Sin_n = List_SIN_N.ToArray(); double[] Sin_K = List_SIN_K.ToArray(); Dat_cublic_spline.Cal.CubicSplineInterpolation Sin_CSN = new Dat_cublic_spline.Cal.CubicSplineInterpolation(Sin_nm, Sin_n); Dat_cublic_spline.Cal.CubicSplineInterpolation Sin_CSK = new Dat_cublic_spline.Cal.CubicSplineInterpolation(Sin_nm, Sin_K); newdatfile.Close(); #endregion #region 3. SiO2_nm 읽기 string[] string_sio2_nm = File.ReadAllLines("SIO2_nm.txt", Encoding.Default); List <SiData> List_sion_NM = new List <SiData>(); StreamWriter newSio2Txt = new StreamWriter(new FileStream("SIO2_nm.txt", FileMode.Open)); foreach (var lines in string_sio2_nm) { string[] splitData = lines.Split(replace2SiO2, StringSplitOptions.RemoveEmptyEntries); List_sion_NM.Add(new SiData { NM = splitData[0], N = splitData[1], K = splitData[2] }); } List <double> List_SiO2_NM = new List <double>(); List <double> List_SiO2_N = new List <double>(); List <double> List_SiO2_K = new List <double>(); for (int i = 1; i < string_sio2_nm.Length; i++) { ChangeX = double.Parse(List_sion_NM[i].NM); ChangeY1 = double.Parse(List_sion_NM[i].N); ChangeY2 = double.Parse(List_sion_NM[i].K); List_SiO2_NM.Add(ChangeX); List_SiO2_N.Add(ChangeY1); List_SiO2_K.Add(ChangeY2); } double[] SiO2_nm = List_SiO2_NM.ToArray(); double[] SiO2_n = List_SiO2_N.ToArray(); double[] SiO2_k = List_SiO2_K.ToArray(); Cal.CubicSplineInterpolation SiO2_CSN = new Cal.CubicSplineInterpolation(SiO2_nm, SiO2_n); Cal.CubicSplineInterpolation SiO2_CSK = new Cal.CubicSplineInterpolation(SiO2_nm, SiO2_k); newSio2Txt.Close(); #endregion #region 4. Si_nm 읽기 string[] string_si_nm = File.ReadAllLines("Si_nm.txt", Encoding.Default); List <SiData> List_si_NM = new List <SiData>(); StreamWriter newSiTxt = new StreamWriter(new FileStream("Si_nm.txt", FileMode.Open)); foreach (var lines in string_si_nm) { string[] splitData = lines.Split(replace2SiO2, StringSplitOptions.RemoveEmptyEntries); List_si_NM.Add(new SiData { NM = splitData[0], N = splitData[1], K = splitData[2] }); } List <double> List_Si_NM = new List <double>(); List <double> List_Si_N = new List <double>(); List <double> List_Si_K = new List <double>(); for (int i = 1; i < string_si_nm.Length; i++) { ChangeX = double.Parse(List_si_NM[i].NM); ChangeY1 = double.Parse(List_si_NM[i].N); ChangeY2 = double.Parse(List_si_NM[i].K); List_Si_NM.Add(ChangeX); List_Si_N.Add(ChangeY1); List_Si_K.Add(ChangeY2); } double[] Si_nm = List_Si_NM.ToArray(); double[] Si_n = List_Si_N.ToArray(); double[] Si_k = List_Si_K.ToArray(); CubicSplineInterpolation Si_CSN = new CubicSplineInterpolation(Si_nm, Si_n); CubicSplineInterpolation Si_CSK = new CubicSplineInterpolation(Si_nm, Si_k); newSiTxt.Close(); #endregion #region 5. SiN_New 파일 쓰기 StreamWriter ChangeTxt = new StreamWriter(new FileStream("SIN_New.txt", FileMode.Create)); List <NewData> List_SiN = new List <NewData>(); ChangeTxt.WriteLine("wavelength(nm)\tn\tk"); for (int i = 1; i < Dat_double_wavelength.Length; i++) { if (Dat_double_wavelength[i] > 350 && Dat_double_wavelength[i] < 980) { List_SiN.Add(new NewData { NEWnm = Dat_double_wavelength[i], NEWN = (double)Sin_CSN.Interpolate(Dat_double_wavelength[i]), NEWK = (double)Sin_CSK.Interpolate(Dat_double_wavelength[i]) }); } } for (int i = 0; i < List_SiN.Count; i++) { if (List_SiN[i].NEWnm >= 350) { ChangeTxt.WriteLine("{0}\t{1}\t{2}", List_SiN[i].NEWnm, List_SiN[i].NEWN, List_SiN[i].NEWK); } } ChangeTxt.Close(); #endregion #region 5. SiN_New_700 파일 쓰기 StreamWriter ChangeTxt_700 = new StreamWriter(new FileStream("SIN_New_700.txt", FileMode.Create)); List <NewData> List_SiN_700 = new List <NewData>(); ChangeTxt_700.WriteLine("wavelength(nm)\tn\tk"); for (int i = 1; i < Sort_Dat_Wave.Length; i++) { if (Sort_Dat_Wave[i] > 350 && Sort_Dat_Wave[i] < 980) { List_SiN_700.Add(new NewData { NEWnm = Sort_Dat_Wave[i], NEWN = (double)Sin_CSN.Interpolate(Sort_Dat_Wave[i]), NEWK = (double)Sin_CSK.Interpolate(Sort_Dat_Wave[i]) }); } } for (int i = 0; i < List_SiN.Count; i++) { if (List_SiN[i].NEWnm >= 350) { ChangeTxt_700.WriteLine("{0}\t{1}\t{2}", List_SiN_700[i].NEWnm, List_SiN_700[i].NEWN, List_SiN_700[i].NEWK); } } ChangeTxt_700.Close(); #endregion #region 6. SiO2_new 파일 쓰기 StreamWriter ChageSio2Txt = new StreamWriter(new FileStream("SiO2_new.txt", FileMode.Create)); List <NewData> List_SiO2 = new List <NewData>(); ChageSio2Txt.WriteLine("wavelength(nm)\tn\tk"); //i=0은 해더, Dat_Double_NM= 파장값 ~.dat파일에서 뽑아온거 for (int i = 0; i < Dat_double_wavelength.Length; i++) { if (Dat_double_wavelength[i] > 980) { break; } List_SiO2.Add(new NewData { NEWnm = Dat_double_wavelength[i], NEWN = (double)SiO2_CSN.Interpolate(Dat_double_wavelength[i]), NEWK = (double)SiO2_CSK.Interpolate(Dat_double_wavelength[i]) }); ChageSio2Txt.WriteLine("{0}\t{1}\t{2}", List_SiO2[i].NEWnm, List_SiO2[i].NEWN, List_SiO2[i].NEWK); } ChageSio2Txt.Close(); #endregion #region 6. SiO2_new_700 파일 쓰기 StreamWriter ChageSio2Txt_700 = new StreamWriter(new FileStream("SiO2_new_700.txt", FileMode.Create)); List <NewData> List_SiO2_700 = new List <NewData>(); ChageSio2Txt_700.WriteLine("wavelength(nm)\tn\tk"); //i=0은 해더, Dat_Double_NM= 파장값 ~.dat파일에서 뽑아온거 for (int i = 0; i < Sort_Dat_Wave.Length; i++) { if (Sort_Dat_Wave[i] > 980) { break; } List_SiO2_700.Add(new NewData { NEWnm = Sort_Dat_Wave[i], NEWN = (double)SiO2_CSN.Interpolate(Sort_Dat_Wave[i]), NEWK = (double)SiO2_CSK.Interpolate(Sort_Dat_Wave[i]) }); ChageSio2Txt_700.WriteLine("{0}\t{1}\t{2}", List_SiO2_700[i].NEWnm, List_SiO2_700[i].NEWN, List_SiO2_700[i].NEWK); } ChageSio2Txt_700.Close(); #endregion #region 7. Si_new 파일 쓰기 StreamWriter ChageSiTxt = new StreamWriter(new FileStream("Si_new.txt", FileMode.Create)); List <NewData> List_Si = new List <NewData>(); ChageSiTxt.WriteLine("wavelength(nm)\tn\tk"); for (int i = 0; i < Dat_double_wavelength.Length; i++) { if (Dat_double_wavelength[i] > 980) { break; } List_Si.Add(new NewData { NEWnm = Dat_double_wavelength[i], NEWN = (double)Si_CSN.Interpolate(Dat_double_wavelength[i]), NEWK = (double)Si_CSK.Interpolate(Dat_double_wavelength[i]) }); ChageSiTxt.WriteLine("{0}\t{1}\t{2}", List_Si[i].NEWnm, List_Si[i].NEWN, List_Si[i].NEWK); } ChageSiTxt.Close(); #endregion #region 7. Si_new_700 파일 쓰기 StreamWriter ChageSiTxt_700 = new StreamWriter(new FileStream("Si_new_700.txt", FileMode.Create)); List <NewData> List_Si_700 = new List <NewData>(); ChageSiTxt_700.WriteLine("wavelength(nm)\tn\tk"); for (int i = 0; i < Sort_Dat_Wave.Length; i++) { if (Sort_Dat_Wave[i] > 980) { break; } List_Si_700.Add(new NewData { NEWnm = Sort_Dat_Wave[i], NEWN = (double)Si_CSN.Interpolate(Sort_Dat_Wave[i]), NEWK = (double)Si_CSK.Interpolate(Sort_Dat_Wave[i]) }); ChageSiTxt_700.WriteLine("{0}\t{1}\t{2}", List_Si_700[i].NEWnm, List_Si_700[i].NEWN, List_Si_700[i].NEWK); } ChageSiTxt_700.Close(); #endregion }
public void FixedFirstDerivativeFitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError) { IInterpolation interpolation = new CubicSplineInterpolation(_t, _x, SplineBoundaryCondition.FirstDerivative, 1.0, SplineBoundaryCondition.FirstDerivative, -1.0); Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); var actual = interpolation.DifferentiateAll(t); Assert.AreEqual(x, actual.Item1, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t); }
public void NaturalSupportsLinearCase(int samples) { double[] x, y, xtest, ytest; LinearInterpolationCase.Build(out x, out y, out xtest, out ytest, samples); IInterpolation interpolation = new CubicSplineInterpolation(x, y); for (int i = 0; i < xtest.Length; i++) { Assert.AreEqual(ytest[i], interpolation.Interpolate(xtest[i]), 1e-15, "Linear with {0} samples, sample {1}", samples, i); } }
public void NaturalFitsAtSamplePoints() { IInterpolation interpolation = new CubicSplineInterpolation(_t, _x); for (int i = 0; i < _x.Length; i++) { Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i); var actual = interpolation.DifferentiateAll(_t[i]); Assert.AreEqual(_x[i], actual.Item1, "B Exact Point " + i); } }
public void NaturalFitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError) { IInterpolation interpolation = new CubicSplineInterpolation(_t, _x); Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); var actual = interpolation.DifferentiateAll(t); Assert.AreEqual(x, actual.Item1, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t); }
public void FixedSecondDerivativeFitsAtSamplePoints() { IInterpolation interpolation = new CubicSplineInterpolation(_t, _x, SplineBoundaryCondition.SecondDerivative, -5.0, SplineBoundaryCondition.SecondDerivative, -1.0); for (int i = 0; i < _x.Length; i++) { Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i); var actual = interpolation.DifferentiateAll(_t[i]); Assert.AreEqual(_x[i], actual.Item1, "B Exact Point " + i); } }
public void FixedSecondDerivativeFitsAtArbitraryPointsWithMaple( [Values(-2.4, -0.9, -0.5, -0.1, 0.1, 0.4, 1.2, 10.0, -10.0)] double t, [Values(-.8999999999999999993, 1.7590357142857142857, .41517857142857142854, -.82010714285714285714, -1.1026071428571428572, -1.0211428571428571429, .31771428571428571421, 39, -37)] double x, [Values(1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-13, 1e-12)] double maxAbsoluteError) { IInterpolation interpolation = new CubicSplineInterpolation(_t, _x, SplineBoundaryCondition.SecondDerivative, -5.0, SplineBoundaryCondition.SecondDerivative, -1.0); Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); double interpolatedValue; double secondDerivative; interpolation.Differentiate(t, out interpolatedValue, out secondDerivative); Assert.AreEqual(x, interpolatedValue, maxAbsoluteError, "Interpolation as by-product of differentiation at {0}", t); }