Mar
28
2014
0

Scientific Computing Lab TM 2

from graphics import *
from math import *

result = 0

def main():
win = GraphWin(“Pi Approx”, 550, 450)
win.setCoords(0.0, 0.0, 3.0, 4.0)
Text(Point(1,3.25), “Number of Terms:”).draw(win)
Text(Point(0.86,1.5), “Value of pi:”).draw(win)
Text(Point(0.86,1.75), “The Result Data”).draw(win)
Text(Point(0.86,1.25), “Sum of This Series:”).draw(win)
Text(Point(0.86,0.75), “True Fractional Relative Error:”).draw(win)
Text(Point(0.86,0.5), “True Percent Relative Error:”).draw(win)
Text(Point(0.86,1), “True Error:”).draw(win)

input = Entry(Point(2,3.25), 5)
input.setText(“0”)
input.setFill(“white”)
input.draw(win)
Perror = Text(Point(2, 0.5),””)
Rerror = Text(Point(2,0.75),””)
error = Text(Point(2,1), “”)
sum_of_terms = Text(Point(2,1.25),””)
math_pi = Text(Point(2,1.5),””)
sum_of_terms.setStyle(“italic”)
math_pi.setStyle(“italic”)
error.setStyle(“italic”)
Rerror.setStyle(“italic”)
Perror.setStyle(“italic”)
sum_of_terms.draw(win)
math_pi.draw(win)
error.draw(win)
Rerror.draw(win)
Perror.draw(win)
button = Text(Point(1.5,2.5),”Approx”)
button.setFill(“red”)
rect = Rectangle(Point(1.10,2.75),Point(1.90,2.25))
rect.setFill(“green”)
rect.draw(win)
button.draw(win)
win.getMouse()

a = eval(input.getText())
global result
for x in range(1, a+1):
divisor = 2 * x – 1
if x%2==0:
result = result – (4.0/divisor)
else:
result = result + (4.0/divisor)

sum_of_terms.setText(str(result))
math_pi.setText(str(pi))
error.setText(str(pi-result))
Rerror.setText(str((pi-result)/pi))
Perror.setText(str(((pi-result)/pi)*100)+”%”)
button.setText(“Quit”)
win.getMouse()
win.close()

main()

hasil

Read more
Mar
14
2014
0

Scientific Computing Lab TM 1

import math

def main():
hasil = 0
print(“Eina Wenny Natasha M”)
print(“1601235666”)
print(“04PAW”)
print(“\n”)
print(“This program approximates the value of pi by summing of terms in a given series.\n”)
a = int(input(“Enter the number of terms to sum: “))

#Hitung
for x in range(1, a+1):
divisor = 2 * x – 1
if x % 2 == 0:
hasil = hasil – (4.0/divisor)
else:
hasil = hasil + (4.0/divisor)

print(“\nThe Result Data:”)
print(“The Value of math.pi = ” + str(math.pi))
print(“The Sum of the First %d Terms of This Series = ” %(a) + str(hasil))
print(“True Error(Et) = “, str(math.pi-hasil))
print(“True Fractional Relative Error = “, str((math.pi-hasil)/math.pi))
print(“True Percent Relative Error = “, str(((math.pi-hasil)/math.pi)*100), “%”)

main()

Eina Wenny Natasha Magdalena

1601235666

04 PAW

 

hasil

Read more
Mar
11
2014
0

Hello world!

Welcome to Binusian blog.
This is the first post of any blog.binusian.org member blog. Edit or delete it, then start blogging!
Happy Blogging 🙂

Read more

Powered by WordPress. Kredit, Streaming Audio | Theme by TheBuckmaker.