Want to make a function get the result of this Equation?
I want to make a function to get the result of (T) in this Equation
T = 1 /( ( 1-(f/g)^2 ) * 0.5 )
if f and g , are taken from the user as开发者_高级运维 text box input using C#
Well:
double f = ... // take input
double g = ... // take input
double quot = f / g;
double t = 2.0 / (1 - quot * quot);
As far as the take input part is concerned because it is the user entering this value you will probably get a string that you will need to parse back to a number:
double f = double.Parse(someTextBox.Text);
And if you wanted to handle errors gracefully you could use the TryParse method.
Your equation can be put into C# almost as-is. Just switch the ^
(exponent in math notation, Xor in C#) to Math.Pow
, and that's it.
double f = double.Parse(this.textBoxF.Text);
double g = double.Parse(this.textBoxG.Text);
double result = 1 /( ( 1-Math.Pow(f/g, 2) ) * 0.5 )
I think I understand what you're trying to do here. Try this:
double f = double.Parse(text_f.Text);
double g = double.Parse(text_g.Text);
double T = 1 / ((1 - Math.Pow(f / g, 2)) * 0.5);
精彩评论