Skip to content

Commit daaad1b

Browse files
authored
Add files via upload
1 parent ea44d57 commit daaad1b

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

ex4_3FindingMoreRoots.pyde

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from math import sqrt
2+
#set the range of x-values
3+
xmin = -10
4+
xmax = 10
5+
6+
#range of y-values
7+
ymin = -10
8+
ymax = 10
9+
10+
#calculate the range
11+
rangex = xmax - xmin
12+
rangey = ymax - ymin
13+
14+
def setup():
15+
global xscl, yscl
16+
size(600,600)
17+
xscl = width / rangex
18+
yscl = -height / rangey
19+
20+
def draw():
21+
global xscl, yscl
22+
background(255) #white
23+
translate(width/2,height/2) #cyan lines
24+
grid(xscl, yscl)
25+
graphFunction()
26+
27+
def grid(xscl, yscl):
28+
strokeWeight(1)
29+
stroke(0,255,255)
30+
for i in range(xmin,xmax + 1):
31+
line(i*xscl,ymin*yscl,i*xscl,ymax*yscl)
32+
line(xmin*xscl,i*yscl,xmax*xscl,i*yscl)
33+
34+
#creating x-axis and y-axis lines
35+
stroke(0) #black
36+
line(0, ymin*yscl, 0, ymax*yscl)
37+
line(xmin*xscl, 0, xmax*xscl, 0)
38+
39+
def f(x):
40+
return 2*x**2 + 7*x - 15
41+
42+
def graphFunction():
43+
x=xmin
44+
while x<=xmax:
45+
stroke(255,0,0)
46+
fill(0,0,255)
47+
line(x*xscl, f(x)*yscl, (x+0.1)*xscl, f(x+0.1)*yscl)
48+
x+=0.1
49+
50+
def quad(a, b, c):
51+
return (-b+(sqrt(b**2 - 4*a*c)))/(2*a), (-b-(sqrt(b**2 - 4*a*c)))/(2*a)
52+
53+
print(quad(2,7,-15))

0 commit comments

Comments
 (0)