Chapter 18 Variation

Example 18_1 pgno:225

In [3]:
#y=a*x**2+b
import numpy
import matplotlib
from matplotlib import pyplot
%matplotlib inline
import numpy

x=numpy.array([0, 0.5, 1, 1.5, 2, 2.5]);
y=numpy.array([-10, -9.25, -7, -3.25, 2, 8.75]);
pyplot.plot(x**2,y);
pyplot.title("Graph of y=ax**2+b")
pyplot.xlabel("x axis")
pyplot.ylabel("y axis");

pyplot.grid()
pyplot.show()


#the values of a & b can be found by substituting two suitable points(x,y)in a*x**2+b-y=0
x=1;y=-7;#p1=-a+b+7 
x=4;y=2;#p2=4*a+b-2
a=('a');
p='-a+7-(4*a-2)';
#a=numpy.roots(p);
x=1;y=-7;
#b=y-a*(x**2);
x=('x');
#(or) by inspection of graph, intercept on y-axis is (i.e., b) is -10 and a,the gradient of the line,is 3
print("\n Hence, the law is\n")
x=('x');
y='3*x**2-10'
print("or by solving by the method of Section 185")
#ny=a*x**2+b

print y
 Hence, the law is

or by solving by the method of Section 185
3*x**2-10

Example 18_2 pgno:229

In [5]:
import numpy
import matplotlib
from matplotlib import pyplot
%matplotlib inline
x=numpy.linspace(-3,3,11);
y=x**3;
pyplot.plot(x,y);
pyplot.title("Parabola curve")
pyplot.xlabel("x axis")
pyplot.ylabel("y axis")
pyplot.legend("y=x^2");
pyplot.grid()
pyplot.show()