from __future__ import division
lbm=9999# #cm, measured length of bridge
lrm=9##cm, measured length of rivet
lbt=10000##cm, true length of bridge
lrt=10##cm,true length of rivet
#calculating true error below#
Etb=lbt-lbm##cm, true error in bridge
Etr=lrt-lrm##cm, true error in rivet
#calculating percent relative error below
etb=Etb*100/lbt##percent relative error for bridge
etr=Etb*100/lrt##percent relative error for rivet
print "a. The true error is"
print "for the bridge : ",Etb,"cm"
print "for the rivet : ",Etr,"cm"
print "b. The percent relative error is"
print "for the bridge : ",etb,"cm"
print "for the rivet : ",etr,"cm"
from __future__ import division
from math import factorial
n=3##number of significant figures
es=0.5*(10**(2-n))##percent, specified error criterion
x=0.5#
f=[]
f.append(1)##first estimate f=e**x = 1
ft=1.648721##true value of e**0.5=f
et=[]
et.append((ft-f[0])*100/ft)
ea=[]
ea.append(100)
i=1
while ea[i-1]>=es:
f.append(f[(i-1)]+(x**(i-1))/(factorial(i-1)))
et.append((ft-f[(i)])*100/ft)
ea.append((f[(i)]-f[(i-1)])*100/f[(i)])
i=i+1#
print "Terms\t\t\tResult\t\t\t\tet(%)\t\t\t\tea(%)"
print '-'*100
for j in range(0,i-1):
print j+1,'\t\t\t%0.5f'%f[j],'\t\t\t',et[j],'\t\t\t',ea[j]
print '-'*100
n=16##no of bits
num=0#
for i in range(0,(n-1)):
num=num+(1*(2**i))#
print "Thus a 16-bit computer word can store decimal integers ranging from",(-1*num),"to",num
n=7##no. of bits
#the maximum value of exponents is given by
max=1*(2**1)+1*(2**0)#
#mantissa is found by
mantissa=1*(2**-1)+0*(2**-3)+0*(2**-3)#
num=mantissa*(2**(max*-1))##smallest possible positive number for this system
print "The smallest possible positive number for this system is : ",num
b=2##base
t=3##number of mantissa bits
E=2**(1-t)##epsilon
print "value of epsilon=",E
num=input("Input a number: ")
Sum=0#
for i in range(0,100000):
Sum=Sum+num#
print "The number summed up 100,000 times is=",Sum
a=1#
b=3000.001#
c=3#
#the roots of the quadratic equation x**2+3000.001*x+3=0 are found as
D=(b**2)-4*a*c#
x1=(-b+(D**0.5))/(2*a)#
x2=(-b-(D**0.5))/(2*a)#
print "The roots of the quadratic equation (x**2)+(3000.001*x)+3=0 are = ",x1,'&',x2
from math import exp
def f(x):
y=exp(x)
return y
Sum=1#
test=0#
i=0#
term=1#
x=input("Input value of x:")
while Sum!=test:
print "sum:",Sum,"term:",term,"i:",i
print "-------------------------------------"
i=i+1#
term=term*x/i#
test=Sum#
Sum=Sum+term#
print "Exact Value:",f(x)