Chapter 8 Graphical Representation of Quantities

Example 8_1 pgno:92

In [1]:
import numpy 
import matplotlib
from matplotlib import pyplot
%matplotlib inline

AGE=numpy.array([25, 30, 35, 40, 45, 50])
premium_in_D=numpy.array([2.33, 2.59, 2.91, 3.31, 3.81, 4.53])
pyplot.plot(AGE,premium_in_D);
pyplot.title('Annual Premiums charged by an insurance company')
pyplot.xlabel('AGE(in years)')
pyplot.ylabel('premium_in_$')
pyplot.grid()
AGE=43;premium_in_D=3.6;
pyplot.plot(AGE,premium_in_D);
AGE=36;premium_in_D=3;
pyplot.plot(AGE,premium_in_D);
pyplot.plot(25,2.0,'o')
pyplot.show()

Example 8_2 pgno:93

In [2]:
import numpy 
import matplotlib
from matplotlib import pyplot
%matplotlib inline

length1=numpy.array([100, 120, 170, 220]);
resistance=numpy.array([2.5, 3, 4.25, 5.5]);
pyplot.plot(length1,resistance);
pyplot.title('Relation between Resistances and Length')
pyplot.xlabel('length_in_meters')
pyplot.ylabel('resistance_in_ohms')
pyplot.grid()
length1=200;
resistance=5;
pyplot.plot(length1,resistance);

pyplot.plot(250,6.2,'o')#this point is called extrapolation 

pyplot.show()

Example 8_3 pgno:95

In [3]:
import numpy
import matplotlib
from matplotlib import pyplot
%matplotlib inline

time=numpy.array([0, 1, 2, 3, 4, 5]);
distance=numpy.array([0, 2, 8, 18, 32, 50]);
pyplot.plot(time,distance)
pyplot.title("Relation between Time and Distance")
pyplot.ylabel("time t in sec")
pyplot.xlabel("distance in meters")

pyplot.grid()
#ex1:distance passed over in 3.6s
print"EX1: \nfrom curve, it is 26m. the actual distance from formula is 25.92m"
#ex2:time to travel 42m
print"EX2: \nline from 42m on distance axis that touches the curve at 4.6s.the mechanics formula gives 4.58s"

pyplot.show()
EX1: 
from curve, it is 26m. the actual distance from formula is 25.92m
EX2: 
line from 42m on distance axis that touches the curve at 4.6s.the mechanics formula gives 4.58s