Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

THIS IS A PYTHON HOMEWORK

## Consider the Following Equations

### Equations:
\[
\sum_{i=1}^{n} (3i - 2)^2 = \frac{1}{2}n(6n^2 - 3n - 1) \quad (32)
\]

\[
\sum_{i=1}^{n} i^3 = \frac{1}{4}n^2(n + 1)^2 \quad (33)
\]

\[
\cos(x) \cdot \cos(2x) \cdots \cos(2^{n-1}x) = \frac{\sin(2^n x)}{2^n \sin(x)} \quad (34)
\]

For the last expression, \( n = 1, 2, 3, \ldots \) and \(\sin(x) \neq 0\).

### Some Helpful Background:
Before we move ahead, note that equations 32, 33, and 34 are examples of analytical (closed-form) solutions. This means that you can either solve them via the formulas as shown or calculate each term individually, and both solutions will match. Isn’t it amazing that some people figured out that rather than calculating and adding each term in a loop, you can directly get the final result by plugging the values in the formula?

While this is fascinating to some of us, analytical solutions are not available for all problems. These examples are provided to help check that both loop-based (calculating each term iteratively) and closed-form solutions match. Equations 35 to 37 demonstrate this for \( n = 5 \).

### Loop-Based Calculation:
\[
\sum_{i=1}^{5} (3i - 2)^2 = (3 - 2)^2 + (6 - 2)^2 + (9 - 2)^2 + (12 - 2)^2 + (15 - 2)^2 \quad (35)
\]

Breaking it down:
\[
= 1^2 + 4^2 + 7^2 + 10^2 + 13^2 = 1 + 16 + 49 + 100 + 169 = 335 \quad (36)
\]

### Closed-Form Solution:
\[
= (1/2)5(6(5^2) - 3(5)) - 1 = (5
expand button
Transcribed Image Text:## Consider the Following Equations ### Equations: \[ \sum_{i=1}^{n} (3i - 2)^2 = \frac{1}{2}n(6n^2 - 3n - 1) \quad (32) \] \[ \sum_{i=1}^{n} i^3 = \frac{1}{4}n^2(n + 1)^2 \quad (33) \] \[ \cos(x) \cdot \cos(2x) \cdots \cos(2^{n-1}x) = \frac{\sin(2^n x)}{2^n \sin(x)} \quad (34) \] For the last expression, \( n = 1, 2, 3, \ldots \) and \(\sin(x) \neq 0\). ### Some Helpful Background: Before we move ahead, note that equations 32, 33, and 34 are examples of analytical (closed-form) solutions. This means that you can either solve them via the formulas as shown or calculate each term individually, and both solutions will match. Isn’t it amazing that some people figured out that rather than calculating and adding each term in a loop, you can directly get the final result by plugging the values in the formula? While this is fascinating to some of us, analytical solutions are not available for all problems. These examples are provided to help check that both loop-based (calculating each term iteratively) and closed-form solutions match. Equations 35 to 37 demonstrate this for \( n = 5 \). ### Loop-Based Calculation: \[ \sum_{i=1}^{5} (3i - 2)^2 = (3 - 2)^2 + (6 - 2)^2 + (9 - 2)^2 + (12 - 2)^2 + (15 - 2)^2 \quad (35) \] Breaking it down: \[ = 1^2 + 4^2 + 7^2 + 10^2 + 13^2 = 1 + 16 + 49 + 100 + 169 = 335 \quad (36) \] ### Closed-Form Solution: \[ = (1/2)5(6(5^2) - 3(5)) - 1 = (5
```python
4   def closed(n):
5       return (1/4)*(n**2)*(n+1)**2
6       sum = 0
7       #complete bounded loop here
8       return [sum,closed(stop)]
9       
10  def iv(stop):
11      def closed(n):
12          return (1/2)*n*(6*(n**2)-(3*n)-1)
13      sum = 0
14      #complete bounded loop here
15      return [sum, closed(stop)]
16      
17  def vi(x,stop):
18      def closed(x,n):
19          return math.sin(x+(2**n))/((2**n)*math.sin(x))
20      prod = 1
21      #complete bounded loop here
22      return [prod,closed(x,stop)]
23      
24  print(iii(5))
25  print(iv(5))
26  print(vi(math.pi,5))
```

**Explanation:**

This Python code contains three functions: `closed`, `iv`, and `vi`, each designed to calculate a mathematical expression based on the given parameters and return a list of values. The functions `iv` and `vi` contain nested functions also named `closed`.

- **Function `closed(n)`**: 
  - Computes an expression using the formula \((1/4) \cdot (n^2) \cdot (n+1)^2\).
  - Returns a list containing the sum (uninitialized loop) and the result of the expression with `n` equal to `stop`.

- **Function `iv(stop)`**:
  - Contains a nested function `closed(n)` which computes a different formula: \((1/2) \cdot n \cdot (6 \cdot (n^2) - (3 \cdot n) - 1)\).
  - Returns a list with the sum (uninitialized loop) and the result of the nested `closed(stop)`.

- **Function `vi(x, stop)`**:
  - Contains a nested function `closed(x, n)` which calculates using trigonometric functions: \(\frac{\sin(x+(2^n))}{((2^n) \cdot \sin(x))}\).
  - Returns a list with the product (uninitialized loop) and the result of `closed(x, stop)`.

Print statements show outputs
expand button
Transcribed Image Text:```python 4 def closed(n): 5 return (1/4)*(n**2)*(n+1)**2 6 sum = 0 7 #complete bounded loop here 8 return [sum,closed(stop)] 9 10 def iv(stop): 11 def closed(n): 12 return (1/2)*n*(6*(n**2)-(3*n)-1) 13 sum = 0 14 #complete bounded loop here 15 return [sum, closed(stop)] 16 17 def vi(x,stop): 18 def closed(x,n): 19 return math.sin(x+(2**n))/((2**n)*math.sin(x)) 20 prod = 1 21 #complete bounded loop here 22 return [prod,closed(x,stop)] 23 24 print(iii(5)) 25 print(iv(5)) 26 print(vi(math.pi,5)) ``` **Explanation:** This Python code contains three functions: `closed`, `iv`, and `vi`, each designed to calculate a mathematical expression based on the given parameters and return a list of values. The functions `iv` and `vi` contain nested functions also named `closed`. - **Function `closed(n)`**: - Computes an expression using the formula \((1/4) \cdot (n^2) \cdot (n+1)^2\). - Returns a list containing the sum (uninitialized loop) and the result of the expression with `n` equal to `stop`. - **Function `iv(stop)`**: - Contains a nested function `closed(n)` which computes a different formula: \((1/2) \cdot n \cdot (6 \cdot (n^2) - (3 \cdot n) - 1)\). - Returns a list with the sum (uninitialized loop) and the result of the nested `closed(stop)`. - **Function `vi(x, stop)`**: - Contains a nested function `closed(x, n)` which calculates using trigonometric functions: \(\frac{\sin(x+(2^n))}{((2^n) \cdot \sin(x))}\). - Returns a list with the product (uninitialized loop) and the result of `closed(x, stop)`. Print statements show outputs
Expert Solution
Check Mark
Still need help?
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

you do not do anything with this question, the question ask you to complete all bounded loop in different function.

Solution
Bartleby Expert
by Bartleby Expert
SEE SOLUTION
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

you do not do anything with this question, the question ask you to complete all bounded loop in different function.

Solution
Bartleby Expert
by Bartleby Expert
SEE SOLUTION
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education