Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have attached my code here to count the area under the sin function but when I graph its not going all the way through

I have attached my code here to count the area under the sin function but when I graph its not going all the way through can help me fix that? Its the range from 0 to pi. it should cover all area with rectangle

# sinarea.py

import math from graphics import *

border = 10 height = 500 width = 700 def sine(n): return math.sin(n) def yspot(y): # algebra to rescale points # Y must range from 0 to 1 # use border + ((1-Y)*height) return border+((1-y)*height) win = GraphWin("Example Graph",width+(3*border), height+(2*border)) # extra border for X axis labels # so you should graph in range 20-720, 10-510

win.setBackground("white")

Text(Point(10,yspot(0)), '0').draw(win) Text(Point(10,yspot(0.25)), '.25').draw(win) Text(Point(10,yspot(0.5)), '.50').draw(win) Text(Point(10,yspot(0.75)), '.75').draw(win) Text(Point(10,yspot(1)), '1').draw(win)

rectangle = int(input("Enter the number of rectangle you want to use: ")) print() lower = 0 upper = math.pi step = 0.1 width = (upper - lower) / rectangle area = 0 lc = lower lc1 = lower + step for i in range(rectangle):

value = lower + ( width * i )

areaR = math.sin(value) * width

area = area + areaR nextpoint = Rectangle(Point(12+lc*222,yspot(0)), Point(12+lc1*222,yspot(sine(lc)))) nextpoint.setOutline("red") nextpoint.draw(win) lc = lc1 lc1 = lc1 + step a print(area)

win.getMouse() win.close()

image text in transcribed

Python File Edit Window Help 52% 1 Mon Dec 28 12:04 PM Q E sinarea.py - /Users/dhruvilpatel/Documents/cs 125k/sinarea.py (3.8.5) # sinarea.py inport nath fron graphics import * Example Graph 1 win >>> border = 10 height = 566 width = 70 def sinein): return nath.sinin def Python 3.8.5 Shell Pythan 3.2.5 (v3.8.5:588fbb61bf, Jul 20 2e2e, 12:11:27) Colang 6.0 (clang-688.8.57)] on darwin Tyga "help', 'copyright', 'credits" or "license" for more information. # ex =========== RESTART: /Users/dhruvilpatel/Documents/es125k/sinarea.py ======== # so Enter the number of rectangle you want to use: 18 win. Traceback (most recent call last): File "/users/dhruvilpatel/Documents/cs125k/sinacea.py", line 49, in Text Text NamaError: name 'a' is not defined Text >>> Text =========== RESTART: /Users/dhruvilpatel/Documents/es125k/sinarea.py =========== Text Enter the number of rectangle you want to use: 18 rect 1.9835235375094546 prin lowe uppe step widt area lc = 1c1 for .75 50 25 prin Ln: 17 Cal: 0 win.getMouse) win.close() Ln: 49 Col: 4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions