Chapter 9 The Law of Straight Line and Co ordinates

Example 9_1 pgno:99

In [2]:
#let a-the avg. amount paid. x-no. of customers.  b-the expenses
#net profit is y=ax-b
x=320;y=4.50;
x=250;y=1.00;
#substitute in above equation
import numpy
import matplotlib
from matplotlib import pyplot
%matplotlib inline

#4.5=320*a-b-equ.1;1=250*a-b-equ.2.subbstract equ.2 from 1.
a=0.05;#we get
b=250*a-1;

#x is a polynomial function of degree zerox=poly(0,'x');
#y=numpy.array[(0.05, -11.5)];#equation to straight line
#if there is no profit i.e., y=0

x=0;
for x in range(0,500):
  if(0.05*x-11.5==0):
    print"the number is ",x 
	


cust=numpy.array([230, 240, 270, 300, 350, 380]);
profit=numpy.array([0, 0.5, 2.0, 3.5, 6.0, 7.5]);
pyplot.plot(cust,profit);
pyplot.plot(230,0);
#profit(y) depends on varying no. of customers(x). the no.'s 0.05 & 11.5 remained constant
pyplot.title("the straight line graph"),
pyplot.xlabel("no. of customers")
pyplot.ylabel("profit");
pyplot.legend("y=0.05*x-11.5");
pyplot.grid()
pyplot.show()
the number is  230

Example 9_2 pgno:103

In [3]:
#2*y-4*x=3
import numpy
import matplotlib
from matplotlib import pyplot
%matplotlib inline
#x is a polynomial function of degree zero  x=#poly(0,'x');
x=numpy.array([-2., -1., 0, 1., 1.8, 2.]);
y=numpy.array([0, 0, 0, 0, 0, 0]);
i=0;
for i in range (0,6):
	y[i]=(3.+4.*x[i])/2.;
	i=i+1
print y
y=numpy.array([-2.5, -0.5, 1.5, 3.5, 5.1, 5.5])
pyplot.plot(x,y)
pyplot.plot(0,1.5,'o')#when x=0. 1.5 is intercept on y-axis
pyplot.plot(-0.75,0,'o')#when y=0. -0.75 is intercept on x-axis
pyplot.title('graph of equation 2y-4x-3')
pyplot.xlabel('x axis')
pyplot.ylabel('y axis')
pyplot.grid()
pyplot.show()
[-2  0  1  3  5  5]

Example 9_3 pgno:104

In [4]:
import numpy
import matplotlib
from matplotlib import pyplot
%matplotlib inline
#x is a polynomial function of degree zero  x=#poly(0,'x');
x=numpy.array([-2, -1, 0, 1, 2, 3]);
y=numpy.array([0, 0, 0, 0, 0, 0]);
i=0;
for i in range (0,6):
	y[i]=(1-2*x[i]);
	i=i+1
print y

pyplot.plot(x,y)
pyplot.plot(0,1,'o')#when x=0. 1.5 is intercept on y-axis
pyplot.plot(0.5,0,'o')#when y=0. -0.75 is intercept on x-axis
pyplot.title('graph of equation 2y-4x-3')
pyplot.xlabel('x axis')
pyplot.ylabel('y axis')
pyplot.grid()
pyplot.show()
[ 5  3  1 -1 -3 -5]

Example 9_4 pgno:112

In [5]:
#y=mx+b
import numpy
import matplotlib
from matplotlib import pyplot
%matplotlib inline

x=numpy.array([0, 1, 2, 3]);
y=x;
pyplot.plot(x,y);
y=x+2;
pyplot.plot(x,y);
y=x-3;
pyplot.plot(x,y);
pyplot.title("Equations of the form y=mx+b")
pyplot.xlabel("x axis")
pyplot.ylabel("y axis");
pyplot.legend("y=x")
pyplot.legend("y=x+2")
pyplot.legend("y=x-3")
pyplot.grid()
#m is constant, b is fixed distance. (x,y) vary for different points on the line 

#ex(1)
print"ex(1) In y=4x-7, gradient is 4.Intercept on y-axis is -7"
#ex(2)
print"ex(2) In y=0.05x-11.5, gradient is 0.05 and intercept on y-axis is -11.5"
pyplot.show()
ex(1) In y=4x-7, gradient is 4.Intercept on y-axis is -7
ex(2) In y=0.05x-11.5, gradient is 0.05 and intercept on y-axis is -11.5

Example 9_5 pgno:114

In [10]:
import numpy
import matplotlib
from matplotlib import pyplot
%matplotlib inline
#x is a polynomial function of degree zero  x=#poly(0,'x');
#graph of x+2*y=5
x=numpy.array([0, -1, 2, 5]);
y=numpy.array([0, 0, 0, 0]);
i=0;
for i in range (0,3):
	y[i]=(5-x[i])/2;
	i=i+1
print y
y=numpy.array([2.5, 3, 1.5, 0])
pyplot.plot(x,y);
#graph of 3*x-2*y=7
x=numpy.array([0, -1, 7./8., 4]);
y=numpy.array([0, 0, 0, 0]);
y=(3*x-7)/2;

for i in range (0,3):
	y[i]=(3*x[i]-7)/2;
	i=i+1
print y
y=numpy.array([-3.5, -5, -2.1875, 2.5 ])
pyplot.plot(x,y)
for x in range(1,100):
  if((5-x)/2==(3*x-7)/2):
    break

print"the solution of the equation is"
y=(5-x)/2;
print"x=\ny= ",x,y
pyplot.plot(x,y)


pyplot.plot(x,y)
pyplot.plot(1,3,'x')#when x=0. 1.5 is intercept on y-axis
pyplot.plot(0.5,0,'o')#when y=0. -0.75 is intercept on x-axis
pyplot.title('graph of equation 2y-4x-3')
pyplot.xlabel('x axis')
pyplot.ylabel('y axis')
#pyplot.legend("x+2*y=5","3*x-2*y=7");

pyplot.grid()
pyplot.show()
[2 3 1 0]
[-3.5    -5.     -2.1875  2.5   ]
the solution of the equation is
x=
y=  3 1