private static void doCalculation(NtcTable table, NtcThermistorModel ntc) { Console.WriteLine("------------------------------------------------------------------------"); double[] steinhartHartPolynom = ntc.SteinhartHartPolynom; Console.Write("Steinhart-Hart polynom: "); for (int i = steinhartHartPolynom.Length - 1; i >= 0; i--) { if (steinhartHartPolynom[i] == 0.0) { continue; } string fmt; if (i == 0) { fmt = " {0:E}"; } else if (i == 1) { fmt = " {0:E} * x"; } else { fmt = " {0:E} * x^" + i; } if (i < steinhartHartPolynom.Length - 1) { fmt = " + " + fmt; } Console.Write(fmt, steinhartHartPolynom[i]); } Console.WriteLine("\n"); double maxErr = 0.0; double errTemp = 0.0; IList <double> temperatures = table.Temperatures; foreach (double t in temperatures) { double r = table.getResistance(t); double calcT = ntc.calcTemperature(r); double calcR = ntc.calcResistance(t); double err = Math.Abs(calcT - t); if (err > maxErr) { maxErr = err; errTemp = t; } Console.Write("temperature={0,4:F0}\tresistance={1,8:F1}\tcalculated temperature={2,9:F2}\tcalculated resistance={3,9:F2}\n", t, r, calcT, calcR); } Console.WriteLine(); Console.Write("Maximal error={0,7:F5} at temperature={1,5:F1}\n", maxErr, errTemp); Console.WriteLine("========================================================================\n"); }
private static void doCalculation(NtcTable table, NtcThermistorModel ntc) { Console.WriteLine("------------------------------------------------------------------------"); double[] steinhartHartPolynom = ntc.SteinhartHartPolynom; Console.Write("Steinhart-Hart polynom: "); for (int i = steinhartHartPolynom.Length - 1; i >= 0; i--) { if (steinhartHartPolynom[i] == 0.0) { continue; } string fmt; if (i == 0) { fmt = " {0:E}"; } else if (i == 1) { fmt = " {0:E} * x"; } else { fmt = " {0:E} * x^" + i; } if (i < steinhartHartPolynom.Length - 1) { fmt = " + " + fmt; } Console.Write(fmt, steinhartHartPolynom[i]); } Console.WriteLine("\n"); double maxErr = 0.0; double errTemp = 0.0; IList<double> temperatures = table.Temperatures; foreach (double t in temperatures) { double r = table.getResistance(t); double calcT = ntc.calcTemperature(r); double calcR = ntc.calcResistance(t); double err = Math.Abs(calcT - t); if (err > maxErr) { maxErr = err; errTemp = t; } Console.Write("temperature={0,4:F0}\tresistance={1,8:F1}\tcalculated temperature={2,9:F2}\tcalculated resistance={3,9:F2}\n", t, r, calcT, calcR); } Console.WriteLine(); Console.Write("Maximal error={0,7:F5} at temperature={1,5:F1}\n", maxErr, errTemp); Console.WriteLine("========================================================================\n"); }
/// <summary> /// Constructs a new instance based on an NTC table. </summary> /// <param name="table"> NTC table with T-R pairs. </param> /// <exception cref="NtcException"> in case of missing temperature found. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public NtcThermistorModel(NtcTable table) throws NtcException public NtcThermistorModel(NtcTable table) { this.table = table; int dimension = table.NumberOfTemperatures; x = new double[dimension]; y = new double[dimension]; int i = 0; foreach (double temperature in table.Temperatures) { x[i] = Math.Log(table.getResistance(temperature)); y[i] = 1.0 / (temperature - TABS); i++; } double[][] @base = Base; orthonormal(@base); steinhartHartPolynom = approx(@base); }
static void Main(string[] args) { Console.WriteLine("Thermistor library version 1.0"); Console.WriteLine("Copyright (C) 2007, 2013 - SoftQuadrat GmbH, Germany"); Console.WriteLine(); var line = 0; NtcTable table = new NtcTable("Simu", "Simulated NTC"); try { using (var csv = new CsvReader(new StreamReader("simu.txt"), false)) { while (csv.ReadNextRecord()) { line += 1; //if (csv.Count() != 2) //{ // throw new Exception("Wrong number of tokens encountered in line:\n" + line); //} var temperature = csv[0]; var resistance = csv[1]; table.add(temperature, resistance); } } } catch (IOException e) { throw new Exception(e.Message, e); } NtcThermistorModel ntc = new NtcThermistorSimplifiedModel(table); Console.WriteLine("Simplified Model"); doCalculation(table, ntc); ntc = new NtcThermistorModel(table); Console.WriteLine("Standard Model"); doCalculation(table, ntc); ntc = new NtcThermistorExtendedModel(table); Console.WriteLine("Extended Model"); doCalculation(table, ntc); Console.Read(); }
/// <summary> /// Creates a new instance using the given T-R table. </summary> /// <param name="table"> the T-R table. </param> /// <exception cref="NtcException"> in case of errors </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public NtcThermistorSimplifiedModel(NtcTable table) throws NtcException public NtcThermistorSimplifiedModel(NtcTable table) : base(table) { }