This repository has been archived by the owner on Feb 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculator
69 lines (56 loc) · 1.75 KB
/
Calculator
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import matplotlib.pyplot as plt
import numpy as np
import sympy as sp
#ENTERING THE WINDOW BOUNDS:
start = float(raw_input('enter lower x value; x = '))
end = float(raw_input('enter upper x value; x = '))
start1 = float(raw_input('enter lower y value; y = '))
end1 = float(raw_input('enter upper y value; y = '))
#GRAPHING THE ORIGINAL FUNCTION:
x = np.linspace(start, end, 20000)
d = raw_input("enter function here; y = ")
y = eval(str(d))
plt.plot(x,y,'-k')
#DIFFERENTIATING THE ORIGINAL FUNCTION:
x = sp.Symbol('x')
c = raw_input('enter function without the numpy; y = ')
dydx = sp.diff(c, x)
print dydx
t = dydx
#GRAPHING DY/DX:
x = np.linspace(start,end,20000)
z = raw_input('copy & paste first derivative here with numpy; y = ')
a = eval(str(z))
plt.plot(x,a,'-b')
#DIFFERENTIATING DY/DX TO GET D2Y/DX2:
x = sp.Symbol('x')
d2xdy2 = sp.diff(t, x)
print d2xdy2
#GRAPHING D2Y/DX2:
x = np.linspace(start,end,20000)
L = raw_input('copy & paste second derivative here with numpy; y = ')
l = eval(str(L))
plt.plot(x,l,'-y')
#PLAN B FOR IDENTIFYING THE MAX AND MIN
#lol1 = (a<0)
#lol2 = (a>0)
#plt.plot(x[lol1], y[lol1], lw=3)
#plt.plot(x[lol2],y[lol2],linestyle='--', lw=5)
#MARKING CONCAVITY:
segment1 = (l<0)
segment2 = (l>0)
plt.plot(x[segment1], y[segment1], '-k', lw=1)
plt.plot(x[segment2], y[segment2], '-r', lw=1)
if t == float('inf') or t== float('inf'):
plt.axvline(linewidth=4,color='cyan')
plt.show()
plt.grid()
plt.xlim(start, end)
plt.ylim(start1,end1)
print 'original function when concave down = black'
print 'original function when concave up = red'
#print 'original function when increasing = dashed green line'
#print 'original function when decreasing = thick blue line'
print 'first derivative = blue'
print 'second derviative = yellow'
plt.show()