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
07-08-2012, 01:51 AM #2
Originally posted by GAMER View Post
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!


Where from Green Lantern gave you inspiration for this? I don't see how that works out :p

The following user thanked Ninja for this useful post:

The Open Minded
07-08-2012, 01:54 AM #3
Originally posted by Ninja View Post
Where from Green Lantern gave you inspiration for this? I don't see how that works out :p


It wasn't inspiration I was just watching this and I was doing this in my head.

Originally posted by myself

lol... 4^2 = 16

hmm 4/2 = 2

and 4 * 2 = 8

OMG and 8 * 2 = 16

I wonder if that works out for more numbers

and boom it does...

haha better go post on ngu lol.
07-17-2012, 04:53 AM #4
my bad if i messed up
     tag

[code]// C++ FTW
#include <iostream>
#include <cmath>
#include <iomanip>

int main()
{
double a;
std::cout << "enter number to square root: \n";
std::cin >> a;
std::cin.ignore();

std::cout << sqrt(a);
std::cin.get();
return 0;
}
07-18-2012, 05:08 AM #5
Pichu
RIP PICHU.
(x * (x / 2)) * 2;


This equals fucking x * x ...

x * .5x * 2 = x * 1x = x * x = x^2

You just made something simple even more difficult and longer.

Plus, you can just access the Math class...

The following 4 users say thank you to Pichu for this useful post:

aerosoul94, LEzStarz, Cory
08-05-2012, 06:24 AM #6
how can I simulate a roulette and assing a probability to each number, for example if i took 100 games of a real roulette and the 33 wins 5 times and the 5 only 2, so its more probably that 33 wins instead of 5. how can I simulate that, and assing specific probability to each number. sorry for my english
08-07-2012, 02:39 AM #7
Dan
I'm a god.
Now see I would like math if it were like this. But no instead it's the boringest way possible. No
08-17-2012, 04:14 AM #8
Originally posted by Pichu View Post
(x * (x / 2)) * 2;


This equals fucking x * x ...

x * .5x * 2 = x * 1x = x * x = x^2

You just made something simple even more difficult and longer.

Plus, you can just access the Math class...


I know, I just noticed the pattern, and thought it was weird. Is that so wrong? :fa:
08-17-2012, 06:47 PM #9
Originally posted by GAMER View Post

>Well I think we take squaring and square rooting
>squaring and square rooting
>rooting

Oh gawd math :(
08-18-2012, 01:57 AM #10
way eaiser thx for the post

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo