#x^2-x-1=0
import numpy
x=('x')
y=numpy.array([1, -1, -1])# y=0
print"the solution is \n"
x=numpy.roots(y)
print x
#3*x^2-5*x+1=0
import numpy
x=('x');
y=([3, -5, 1]);# y=0
print"the solution is \n"
x=numpy.roots(y)
print x
import numpy
x=('x')
p1='1/(x-1)';
p2='1/(x+2)';
y='p1-p2';
y1=1./16.;
a=numer(y)*denom(y1);
b=numer(y1)*denom(y);
r=a-b;
print"the solution is \n"
x=numpy.roots([-1, -1, 8])
print 2*x
#x^2-2*x-15=0
import numpy
x=('x');
y=([1, -2, -15]);# y=0
print"the solution is \n"
print("x=,",numpy.roots(y))
#9*x*(x+1)=4
import numpy
x=('x')
y=[9, 9, -4]#9*x*(x+1)-4; #y=0
print"the solution is \n"
print("x=, \n",numpy.roots(y))
#5*x**2+9*x-2=0
from numpy import sqrt
x=('x');
y='5*x**2+9*x-2';
a=5;b=9;c=-2;#from equation we get these values
#using the formula - solution of quadratic equation ax**2+bx+c=0
x=(-b+sqrt(b**2-4*a*c))/(2*a);
print("\t x= \n \n or ",x)
x=(-b-sqrt(b**2-4*a*c))/(2*a);
print(" x=",x)
from math import sqrt
x=('x');
p1='1/(x-1)';
p2=2./3.;
p3='2/(x-3)';
p='(p1+p2-p3)';
p=3*numer(p);#As p=0 and to remove fractions, multiply by 3
a=2;b=-11;c=3;#from equation we get these values
#using the formula - solution of quadratic equation ax**2+bx+c=0
print("the solution is")
x=(-b+sqrt(b**2-4*a*c))/(2*a)
print x
print("or \n")
x=(-b-sqrt(b**2-4*a*c))/(2*a)
print round(x,3)
#given u=160,g=10,h=240
from math import sqrt
#using the formulae "h=u*t-(g*t**2)/2"
u=160;
g=10;
h=240;
t=('t');
r='(240-u*t+(g*t**2)/2)'#u*t-(g*t**2)/2-h=0
a=5;b=-160;c=240;#from equation we get these values
#using the formulae - solution of quadratic equation ax**2+bx+c=0
t=(-b+sqrt(b**2-4*a*c))/(2*a);
t1=(-b-sqrt(b**2-4*a*c))/(2*a);
print("\n the solution is t= or t=\n",round(t,3),round(t1,3))#the answer given in textbook is wrong
import numpy
#let x km/hr is avg. speed for 1st journey
#as velocity=distance/time, time for 1st journey is 84/x hrs
#speed for return journey is 84/(x+4).from given data, this is <1/2 hr than the 1st time
x=('x');
#In algebraic form,(84/x)-(84/(x+4))=1/2
y='(84/x)-(84/(x+4))-1/2'; #y=0. so, numerator=0
x=numpy.roots([-1, -4, 8])
#x=roots(numer(y));
#velocity can't be in negatives.take +ve root
print("avg. speed for 1st journey is x=24km/h")
distance=84;#given
velocity=24;#found
time=distance/velocity;#time for 1st journey
time1=distance/(velocity+4);#time for 2nd journey
print("total_timefhours",time+time1)
#x+y=1, 38x^2-x*y+y^2=37
x=('x');
y='1-x';
#substitute y=1-x in equ. 38x^2-x*y+y^2=37
Y='3*x**2-x*(1-x)+(1-x)**2-37';
x=roots(Y);
#y=1-x;
print('the solutions are: \n')
print(x,y)
#x+y=19, xy=84
x=('x');
#substitute y=19-x in xy=84
Y='x*(19-x)-84';
x=roots(Y);
print('the solutions are: \n')
print("(x,y)=() \n",x)
print 'y=19-x'
#x**2+y**2=89, xy=40
import numpy
x=('x');
#substitute y=40/x in x**2+y**2=89
Y='x**2+(40/x)**2-89';
x=numpy.roots([1, 0, -89, 0, -1600]);#Y=0, numerator=0
y=roots(89-x**2);
print('the solutions of (x,y) are: \n')
print [x,y]