Post: Math And Programming [Cool]
07-08-2012, 01:46 AM #1
(adsbygoogle = window.adsbygoogle || []).push({}); Well I think we take squaring and square rooting for advantage. I was watching green lantern today and I thought of an amazing equation to generate squaring... now idk how I thought of it but it was faster than doing X * X = Y; lol but anyway... I continued to make a program and made an example how to generate square root in a program using the babylon method Smile

My Square Root Method:
    
public static double square(double x)
{
return (x * (x / 2)) * 2;
}


Now to use in a program just take an input out of a text box and use it with this to output

ie:
    
private void sqrButton_Click(object sender, EventArgs e)
{
Double input = 0;
try { input = Convert.ToDouble(inputBox.Text); }
catch {}
outputBox.Text = square(input).ToString();
}




Now this is using the babylonian method of generating a square root and in my opinion it's more accurate than calculators today.. Smile

Square Root:
    
public static double squareRoot(double x, int numberOfCycles)
{
double y = numberOfCycles * square(10);
for (int i = 0; i < numberOfCycles; i++)
{
y = .5 * (y + (x / y));
}
return y;
}


Now how this works is that it runs it through this algorithmn a number of times getting closer and closer to the square root, the higher the number of cycles the more accurate the number will be.

(Note: You might want to use decimal instead of double because decimal (in programming) go to 28 to 29 spots past the decimal as double only does 8 (I think) but decimal uses 4 bits more of ram than double does :p)

Now here is how you would use it in a program:
    
private void sqrRootButton_Click(object sender, EventArgs e)
{
double input = 0;
try { input = Convert.ToDouble(inputBox.Text); }
catch {}
outputBox.Text = squareRoot(input, 9999).ToString();
}




Now I hope you learned how basic squaring, and square rooting work other than just using a calculator or the math.sqrroot class in C# :p I learned something myself and I thought it was cool I came up with my own equation. =D Thanks for reading!
(adsbygoogle = window.adsbygoogle || []).push({});

The following 2 users say thank you to Jakes625 for this useful post:

The Open Minded, X-RAY200
09-02-2012, 04:57 AM #11
oyay
Bounty hunter
you people are cool but y'all have one hell of a nerdy side. i know how the mathematical statement is true but i don't know why it is helpful to u. sorry if u are made or offended but thought i had to say it.

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo