from numpy import arange
from math import exp
%matplotlib inline
from matplotlib.pyplot import plot, title, xlabel, ylabel, show
m=68.1##kg
v=40##m/s
t=10##s
g=9.8##m/s**2
def f(c):
y=g*m*(1-exp(-c*t/m))/c - v#
return y
print "For various values of c and f(c) is found as:"
i=0#
Fc=[]
for c in arange(4,21,4):
i=i+1#
bracket=[c, f(c)]
print bracket
Fc.append(f(c))
c=arange(4,21,4)
plot(c,Fc)
title('f(c) vs c')
xlabel('c')
ylabel('f(c) (m/s)')
show()
from numpy import arange
from math import sin,cos
%matplotlib inline
from matplotlib.pyplot import plot, title, xlabel, ylabel, show
def f(x):
y=sin(10*x)+cos(3*x)#
return y
count=1#
func=[]
val=[]
for i in arange(0.55,1,0.05):
val.append(i)
func.append(f(i))
count=count+1#
plot(val,func)
title("x vs f(x)")
xlabel('x')
ylabel('f(x)')
show()
for v in val:
print '%0.2f'%v,'\t',
from math import exp
m=68.1##kg
v=40##m/s
t=10##s
g=9.8##m/s**2
def f(c):
y=g*m*(1-exp(-c*t/m))/c - v#
return y
x1=12#
x2=16#
xt=14.7802##true value
e=input("enter the tolerable true percent error=")
xr=(x1+x2)/2#
etemp=abs(xr-xt)/xt*100##error
while etemp>e:
if f(x1)*f(xr)>0:
x1=xr#
xr=(x1+x2)/2#
etemp=abs(xr-xt)/xt*100#
if f(x1)*f(xr)<0:
x2=xr#
xr=(x1+x2)/2#
etemp=abs(xr-xt)/xt*100#
if f(x1)*f(xr)==0:
break
print "The result is =",xr
from math import exp
m=68.1##kg
v=40##m/s
t=10##s
g=9.8##m/s**2
def f(c):
y=g*m*(1-exp(-c*t/m))/c - v#
return y
x1=12#
x2=16#
xt=14.7802##true value
e=input("enter the tolerable approximate error=")
xr=(x1+x2)/2#
i=1#
et=abs(xr-xt)/xt*100##error
print "Iteration:",i
print "xl:",x1
print "xu:",x2
print "xr:",xr
print "et:",et,"%"
print "----------------------------------------"
etemp=100#
while etemp>e:
if f(x1)*f(xr)>0:
x1=xr
xr=(x1+x2)/2
etemp=abs(xr-x1)/xr*100
et=abs(xr-xt)/xt*100
if f(x1)*f(xr)<0:
x2=xr
xr=(x1+x2)/2
etemp=abs(xr-x2)/xr*100
et=abs(xr-xt)/xt*100
if f(x1)*f(xr)==0:
break#
i=i+1#
print "Iteration:",i
print "xl:",x1
print "xu:",x2
print "xr:",xr
print "et(%):",et,"%"
print "ea",etemp,"%"
print "----------------------------------------"
print "The result is=",xr
from math import exp
m=68.1##kg
v=40##m/s
t=10##s
g=9.8##m/s**2
def f(c):
y=g*m*(1-exp(-c*t/m))/c - v#
return y
x1=12#
x2=16#
xt=14.7802##true value
e=input("enter the tolerable true percent error=")
xr=x1-(f(x1)*(x2-x1))/(f(x2)-f(x1))#
etemp=abs(xr-xt)/xt*100##error
while etemp>e:
if f(x1)*f(xr)>0:
x1=xr
xr=x1-(f(x1)*(x2-x1))/(f(x2)-f(x1))
etemp=abs(xr-xt)/xt*100
if f(x1)*f(xr)<0:
x2=xr
xr=x1-(f(x1)*(x2-x1))/(f(x2)-f(x1))
etemp=abs(xr-xt)/xt*100
if f(x1)*f(xr)==0:
break
print "The result is=",xr
def f(x):
y=x**10 - 1#
return y
x1=0#
x2=1.3#
xt=1#
#using bisection method
print "BISECTION METHOD:"
xr=(x1+x2)/2#
et=abs(xr-xt)/xt*100##error
print "Iteration:",1
print "xl:",x1
print "xu:",x2
print "xr:",xr
print "et(%):",et,"%"
print "----------------------------------------"
for i in range(2,6):
if f(x1)*f(xr)>0:
x1=xr
xr=(x1+x2)/2
ea=abs(xr-x1)/xr*100#
et=abs(xr-xt)/xt*100#
else:
if f(x1)*f(xr)<0:
x2=xr#
xr=(x1+x2)/2#
ea=abs(xr-x2)/xr*100#
et=abs(xr-xt)/xt*100#
if f(x1)*f(xr)==0:
break
print "Iteration:",i
print "xl:",x1
print "xu:",x2
print "xr:",xr
print "et(%):",et,"%"
print "ea(%)",ea,"%"
print "----------------------------------------"
#using false position method
print "FALSE POSITION METHOD:"
x1=0#
x2=1.3#
xt=1#
xr=x1-(f(x1)*(x2-x1))/(f(x2)-f(x1))##
et=abs(xr-xt)/xt*100##error
print "Iteration:",1
print "xl:",x1
print "xu:",x2
print "xr:",xr
print "et(%):",et,"%"
print "----------------------------------------"
for i in range(2,6):
if f(x1)*f(xr)>0:
x1=xr#
xr=x1-(f(x1)*(x2-x1))/(f(x2)-f(x1))#
ea=abs(xr-x1)/xr*100#
et=abs(xr-xt)/xt*100#
elif f(x1)*f(xr)<0:
x2=xr#
xr=x1-(f(x1)*(x2-x1))/(f(x2)-f(x1))#
ea=abs(xr-x2)/xr*100#
et=abs(xr-xt)/xt*100#
elif f(x1)*f(xr)==0:
break#
print "Iteration:",i
print "xl:",x1
print "xu:",x2
print "xr:",xr
print "et(%):",et,'%'
print "ea(%)",ea,"%"
print "----------------------------------------"