Chapter 7 Simultaneous Equations

Example 7_1 pgno:79

In [11]:
#2x+y=21, 3x+4y=44
import numpy
print"y=21-2*x"
p1=numpy.array([-2, 21])
print"(44-3*x)/4"
p2=numpy.array([-3/4, 44/4])


for x in range(0,20):
  if(21-2*x==(44-3*x)/4):
    print"the number is ",x
    print" the solution is :\n x=  ",x
    break
y=21-2*x;
#"substitute the x value in any one of the above equations"
print" y= ",y
y=21-2*x
(44-3*x)/4
the number is  8
 the solution is :
 x=   8
 y=  5

Example 7_2 pgno:80

In [12]:
import numpy
print"y=15-x; "
p1=numpy.array([-1, 15])
print"Y=3*x-21"
p2=numpy.array([3, -21])
print"p3=p1-p2"
p3=p1-p2
print "the solution is" 

x=numpy.roots(p3)
y=15-x;
print y
y=15-x; 
Y=3*x-21
p3=p1-p2
the solution is
[ 6.]

Example 7_3 pgno:80

In [13]:
import numpy
print"y=(42-2*x)/3;"
p1=numpy.array([-2/3, 42/3])
print"y=5*x-20;"
p2=numpy.array([5, -20])
for x in range(0,20):
  if((42-2*x)/3==5*x-20):
    print"the number is ",x
    print" the solution is :\n x=  ",x
    break

y=5*x-20;
#"substitute the x value in any one of the above equations"
print" y= ",y
print"\n the solution is : \n",x,y
y=(42-2*x)/3;
y=5*x-20;
the number is  6
 the solution is :
 x=   6
 y=  10

 the solution is : 
6 10

Example 7_4 pgno:82

In [14]:
import numpy
print"R1=(1.486-1.2*R2)/0.5;"
p1=numpy.array([-1.2/0.5, 1.486/0.5])
print"R=(4.67+2*R2)/4.5;"
p2=numpy.array([1/2, 4.67/4.5])
print"p3=p1-p2"
p3=p1-p2

R2=numpy.roots(p3)

R1=(1.486-1.2*R2)/0.5
print R1
print R2
#difference in answer is due to round off error
R1=(1.486-1.2*R2)/0.5;
R=(4.67+2*R2)/4.5;
p3=p1-p2
[ 1.03777778]
[ 0.80592593]

Example 7_5 pgno:85

In [15]:
import numpy
print"p1=y=(53-x)/3;"
p1=numpy.array([-1/3, 53/3])
print"p2=(4*x-2)/2;"
p2=numpy.array([2, -1])
print"the solution is : \n"


for x in range(0,100):
  if((53-x)/3==(4*x-2)/2):
    print"the number is ",x



#"substitute the x value in any one of the above equations"
y=(53-x)/3;
print"y=",y
p1=y=(53-x)/3;
p2=(4*x-2)/2;
the solution is : 

the number is  8
y= -16

Example 7_6 pgno:84

In [16]:
import numpy
print"p1=6-4*m"
p1=numpy.array([-4, 6])
print"p2=4.5-2.4*m"
p2=numpy.array([-2.4, 4.5])
print"p3=p1-p2"
p=p1-p2

m=numpy.roots(p)

#substitute this value 
b=6-4*m
#"substitute these values in the equation y=mx+b"

print "y=m*x+b"
p1=6-4*m
p2=4.5-2.4*m
p3=p1-p2
y=m*x+b

Example 7_7 pgno:

In [17]:
#let x=number originally sold at 25p
#let y=number originally sold at 20p
#amounts received for these were 25x pence and 20y pence & their total value was 1100pence =>25x+20y=1100 
import numpy
print"y=(1100-25*x)/20;"
p1=numpy.array([-25/20, 1100/20])
print"y=(1150-20*x)/25;"
p2=numpy.array([-20/25, 1150/25])



for x in range(0,100):
  if((1100-25*x)/20==(1150-20*x)/25):
    print"the number is ",x

#"substitute the x value in any one of the above equations"
y=(1100-25*x)/20;
print"the total no. of books sold was   ",x+y
print"the number originally sold at 25p was ",x
y=(1100-25*x)/20;
y=(1150-20*x)/25;
the number is  20
the total no. of books sold was    30
the number originally sold at 25p was  99