from __future__ import division
from sympy.mpmath import quad
def f(x):
y=(0.2+25*x-200*x**2+675*x**3-900*x**4+400*x**5)
return y
tval=1.640533#
a=0#
b=0.8#
fa=f(a)#
fb=f(b)#
l=(b-a)*((fa+fb)/2)#
Et=tval-l##error
et=Et*100/tval##percent relative error
#by using approximate error estimate
#the second derivative of f
def g(x):
y=-400+4050*x-10800*x**2+8000*x**3
return y
f2x=quad(g,[0,0.8])/(b-a)##average value of second derivative
Ea=-(1/12)*(f2x)*(b-a)**3#
print "The Error Et=",round(Et,3)
print "The percent relative error et=",round(et,3),"%"
print "The approximate error estimate without using the true value=",Ea
from __future__ import division
from sympy.mpmath import quad
def f(x):
y=(0.2+25*x-200*x**2+675*x**3-900*x**4+400*x**5)
return y
a=0#
b=0.8#
tval=1.640533#
n=2#
h=(b-a)/n#
fa=f(a)#
fb=f(b)#
fh=f(h)#
l=(b-a)*(fa+2*fh+fb)/(2*n)#
Et=tval-l##error
et=Et*100/tval##percent relative error
#by using approximate error estimate
#the second derivative of f
def g(x):
y=-400+4050*x-10800*x**2+8000*x**3
return y
f2x=quad(g,[0,0.8])/(b-a)##average value of second derivative
Ea=-(1/12)*(f2x)*(b-a)**3/(n**2)#
print "The Error Et=",round(Et,3)
print "The percent relative error et=",round(et,3),"%"
print "The approximate error estimate without using the true value=",Ea
from numpy import arange, exp
g=9.8##m/s**2# acceleration due to gravity
m=68.1##kg
c=12.5##kg/sec# drag coefficient
def f(t):
from numpy import exp
v=g*m*(1-exp(-c*t/m))/c
return v
tval=289.43515##m
a=0#
b=10#
fa=f(a)#
fb=f(b)#
for i in arange(10,21,10):
n=i#
h=(b-a)/n#
print "No. of segments=",i
print "Segment size=",h
j=a+h#
s=0#
while j<b:
s=s+f(j)#
j=j+h#
l=(b-a)*(fa+2*s+fb)/(2*n)#
Et=tval-l##error
et=Et*100/tval##percent relative error
print "Estimated d=",l,"m"
print et,"et(%)"
print "---------------------------------------------------------"
for i in arange(50,101,50):
n=i#
h=(b-a)/n#
print "No. of segments=",i
print "Segment size=",h
j=a+h#
s=0#
while j<b:
s=s+f(j)#
j=j+h#
l=(b-a)*(fa+2*s+fb)/(2*n)#
Et=tval-l##error
et=Et*100/tval##percent relative error
print "Estimated d=",l,"m"
print "et(%)",et
print "---------------------------------------------------------"
for i in arange(100,201,100):
n=i#
h=(b-a)/n#
print "No. of segments=",i
print "Segment size=",h
j=a+h#
s=0#
while j<b:
s=s+f(j)#
j=j+h#
l=(b-a)*(fa+2*s+fb)/(2*n)#
Et=tval-l##error
et=Et*100/tval##percent relative error
print "Estimated d=",l,"m"
print "et(%)",et
print "---------------------------------------------------------"
for i in arange(200,501,300):
n=i#
h=(b-a)/n#
print "No. of segments=",i
print "Segment size=",h
j=a+h#
s=0#
while j<b:
s=s+f(j)#
j=j+h#
l=(b-a)*(fa+2*s+fb)/(2*n)#
Et=tval-l##error
et=Et*100/tval##percent relative error
print "Estimated d=",l,"m"
print "et(%)",et
print "---------------------------------------------------------"
for i in arange(1000,2001,1000):
n=i#
h=(b-a)/n#
print "No. of segments=",i
print "Segment size=",h
j=a+h#
s=0#
while j<b:
s=s+f(j)#
j=j+h#
l=(b-a)*(fa+2*s+fb)/(2*n)#
Et=tval-l##error
et=Et*100/tval##percent relative error
print "Estimated d=",l,"m"
print "et(%)",et
print "---------------------------------------------------------"
for i in arange(2000,5001,3000):
n=i#
h=(b-a)/n#
print "No. of segments=",i
print "Segment size=",h
j=a+h#
s=0#
while j<b:
s=s+f(j)#
j=j+h#
l=(b-a)*(fa+2*s+fb)/(2*n)#
Et=tval-l##error
et=Et*100/tval##percent relative error
print "Estimated d=",l,"m"
print "et(%)",et
print "---------------------------------------------------------"
for i in arange(5000,10001,5000):
n=i#
h=(b-a)/n#
print "No. of segments=",i
print "Segment size=",h
j=a+h#
s=0#
while j<b:
s=s+f(j)#
j=j+h#
l=(b-a)*(fa+2*s+fb)/(2*n)#
Et=tval-l##error
et=Et*100/tval##percent relative error
print "Estimated d=",l,"m"
print "et(%)",et
print "---------------------------------------------------------"
from __future__ import division
from sympy.mpmath import quad
def f(x):
y=(0.2+25*x-200*x**2+675*x**3-900*x**4+400*x**5)
return y
a=0#
b=0.8#
tval=1.640533#
n=2#
h=(b-a)/n#
fa=f(a)#
fb=f(b)#
fh=f(h)#
l=(b-a)*(fa+4*fh+fb)/(3*n)#
print"l=", round(l,2)
Et=tval-l##error
et=Et*100/tval##percent relative error
#by using approximate error estimate
#the fourth derivative of f
def g(x):
y=-21600+48000*x
return y
f4x=quad(g,[0,0.8])/(b-a)##average value of fourth derivative
Ea=-(1/2880)*(f4x)*(b-a)**5#
print "The Error Et=",round(Et,2)
print "The percent relative error et=",round(et,3),"%"
print "The approximate error estimate without using the true value=",round(Ea,3)
from __future__ import division
from sympy.mpmath import quad
def f(x):
y=(0.2+25*x-200*x**2+675*x**3-900*x**4+400*x**5)
return y
a=0#
b=0.8#
tval=1.640533#
n=4#
h=(b-a)/n#
fa=f(a)#
fb=f(b)#
j=a+h#
s=0#
count=1#
while j<b:
if (-1)**count==-1:
s=s+4*f(j)#
else:
s=s+2*f(j)#
count=count+1#
j=j+h#
l=(b-a)*(fa+s+fb)/(3*n)#
print"l=", round(l,2)
Et=tval-l##error
et=Et*100/tval##percent relative error
#by using approximate error estimate
#the fou:rth derivative of f
def g(x):
y=-21600+48000*x
return y
f4x=quad(g,[0,0.8])/(b-a)##average value of fourth derivative
Ea=-(1/(180*4**4))*(f4x)*(b-a)**5#
print "The Error Et=",round(Et,2)
print "The percent relative error et=",round(et,3),"%"
print "The approximate error estimate without using the true value=",round(Ea,3)
from __future__ import division
from sympy.mpmath import quad
def f(x):
y=(0.2+25*x-200*x**2+675*x**3-900*x**4+400*x**5)
return y
a=0#
b=0.8#
tval=1.640533#
#part a
n=3#
h=(b-a)/n#
fa=f(a)#
fb=f(b)#
j=a+h#
s=0#
count=1#
while j<b:
s=s+3*f(j)#
count=count+1#
j=j+h#
l=(b-a)*(fa+s+fb)/(8)#
print "Part A:"
print "l=",round(l,3)
Et=tval-l##error
et=Et*100/tval##percent relative error
#by using approximate error estimate
#the fourth derivative of f
def g(x):
y=-21600+48000*x
return y
f4x=quad(g,[0,0.8])/(b-a)##average value of fourth derivative
Ea=-(1/6480)*(f4x)*(b-a)**5#
print "The Error Et=",round(Et,2)
print "The percent relative error et=",round(et,3),"%"
print "The approximate error estimate without using the true value=",round(Ea,3)
#part b
n=5#
h=(b-a)/n#
l1=(a+2*h-a)*(fa+4*f(a+h)+f(a+2*h))/6#
l2=(a+5*h-a-2*h)*(f(a+2*h)+3*(f(a+3*h)+f(a+4*h))+fb)/8#
l=l1+l2#
print "---------------------------------------------------"
print "Part B:"
print "l=", round(l,3)
Et=tval-l##error
et=Et*100/tval##percent relative error
print "The Error Et=", round(Et,3)
print "The percent relative error et=", round(et,3), "%"
from __future__ import division
def f(x):
y=(0.2+25*x-200*x**2+675*x**3-900*x**4+400*x**5)
return y
tval=1.640533#
x=[0, 0.12, 0.22, 0.32, 0.36, 0.4 ,0.44 ,0.54 ,0.64 ,0.7 ,0.8]
func=[]
for i in range(0,11):
func.append(f(x[i]))#
l=0#
for i in range(0,10):
l=l+(x[i+1]-x[i])*(func[i]+func[i+1])/2#
print "l=",l
Et=tval-l##error
et=Et*100/tval##percent relative error
print "The Error Et=",Et
print "The percent relative error et=",et,"%"
def f(x):
y=(0.2+25*x-200*x**2+675*x**3-900*x**4+400*x**5)
return y
tval=1.640533#
x=[0, 0.12, 0.22, 0.32, 0.36, 0.4 ,0.44 ,0.54, 0.64, 0.7, 0.8]
func =[]
for i in range(0,11):
func.append(f(x[i]))
l1=(x[1]-x[0])*((f(x[0])+f(x[1]))/2)#
l2=(x[3]-x[1])*(f(x[3])+4*f(x[2])+f(x[1]))/6#
l3=(x[6]-x[3])*(f(x[3])+3*(f(x[4])+f(x[5]))+f(x[6]))/8#
l4=(x[8]-x[6])*(f(x[6])+4*f(x[7])+f(x[8]))/6
l5=(x[9]-x[8])*((f(x[9])+f(x[8]))/2)#
l6=(x[10]-x[9])*((f(x[10])+f(x[9]))/2)#
l=l1+l2+l3+l4+l5+l6#
print "l=",l
Et=tval-l##error
et=Et*100/tval##percent relative error
print "The Error Et=",Et
print "The percent relative error et=",et,"%"
def f(x,y):
t=2*x*y+2*x-x**2-2*y**2+72
return t
Len=8##m,length
wid=6##m,width
a=0#
b=Len#
n=2#
h=(b-a)/n#
a1=0#
b1=wid#
h1=(b1-a1)/n#
fa=f(a,0)#
fb=f(b,0)#
fh=f(h,0)#
lx1=(b-a)*(fa+2*fh+fb)/(2*n)#
fa=f(a,h1)#
fb=f(b,h1)#
fh=f(h,h1)#
lx2=(b-a)*(fa+2*fh+fb)/(2*n)#
fa=f(a,b1)#
fb=f(b,b1)#
fh=f(h,b1)#
lx3=(b-a)*(fa+2*fh+fb)/(2*n)#
l=(b1-a1)*(lx1+2*lx2+lx3)/(2*n)#
avg_temp=l/(Len*wid)#
print"The average termperature is=", avg_temp