Skip to content

Instantly share code, notes, and snippets.

@j0nimost
Created June 14, 2017 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j0nimost/caaf2be6521baf6d3a33873cf58442ff to your computer and use it in GitHub Desktop.
Save j0nimost/caaf2be6521baf6d3a33873cf58442ff to your computer and use it in GitHub Desktop.
Implemeting NCalc to a console application
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NCalc;
namespace Bernoulli_s_Temperature_Formula
{
class Program
{
static void Main(string[] args)
{
/*Bernoulli Application
*
* In this Case study we have a metal bar of temperature of 100F placed in a room
* with a constant temperature of 0F if after 20minutes the metal bar is 50F
*
* Find:
* a) An expression for the temperature of the bar at any time T
*
* b) Time it will take the bar to reach 25F
*
*
* c) Temp of the bar after 10minutes
*/
/* t= time
* k = constant
* C = constant
* T = temperature
*/
//declare my expression for part a)
Expression e = new Expression("Round(T / Exp(t),2)",EvaluateOptions.IgnoreCase);
e.Parameters["T"] = 100.00;
e.Parameters["t"] = 0.00;
double Constant = Convert.ToDouble(e.Evaluate());
Console.WriteLine("Our Constant C is {0}",Constant);
e = new Expression("Round((1/Exp(T/C))/t,4)", EvaluateOptions.IgnoreCase);
e.Parameters["T"] = 50.00;
e.Parameters["C"] = Constant;
e.Parameters["t"] = 20.00;
double valueofK = -Convert.ToDouble(e.Evaluate());
Console.WriteLine("Our constant K is {0}", valueofK);
//part b)
e = new Expression("Round(Log10(T/C)/k,2)",EvaluateOptions.IgnoreCase);
e.Parameters["T"] = 25.00;
e.Parameters["C"] = Constant;
e.Parameters["k"] = valueofK;
Console.WriteLine("Time taken will be {0}", e.Evaluate());
//part c)
e = new Expression("Round((C * Exp(k*t)),2)", EvaluateOptions.IgnoreCase);
e.Parameters["C"] = Constant;
e.Parameters["k"] = valueofK;
e.Parameters["t"] = 10.00;//minutes
Console.WriteLine("Temperature will be {0}", e.Evaluate());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment