1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ray Of Light [21]
3 years ago
8

Q3: Summation Write a recursive implementation of summation, which takes a positive integer n and a function term. It applies te

rm to every number from 1 to n including n and returns the sum of the results. # Question 3 def summation(n, term) : ""Return the sum of the first n terms in the sequence defined by term. Implement using recursion! >>> summation(5, lambda x: x * x * x) # 1^3 + 2^3 + 3^3 + 4^3 + 5^3 225 >>> summation(9, lambda x: x + 1) # 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 54 >>> summation(5, lambda x: 2**x) # 241 + 2^2 + 2^3 + 2^4 + 245 62 >>> # Do not use while for loops!

Engineering
1 answer:
harina [27]3 years ago
6 0

Answer:

Here is the recursive function summation:

def summation(n, term):      

   if n == 1:  

       return term(n)

   else:

       return term(n) + summation(n - 1, term)

Explanation:

The function summation() has two arguments where n is a positive integer and term is a function term. term has the lambda function which is a small function having an argument and an expression e.g lambda b: b+20

So the summation() function is a recursive function which returns sum of the first n terms in the sequence defined by term ( a lambda function).

If you want to check if this function works, you can call this function by passing values to it like given in the question.

summation(5, lambda x: 2**x)

Here the value of n is 5 and the term is a lambda function x: 2**x

If you want to see the results of this function on output screen then use:

print(summation(5, lambda x: 2**x))

The print() function will print the results on screen.

This returns the sum of first 5 terms in sequence defined in the function x: 2**x

In recursive methods there are two cases: base case and recursive case. Base case is the stopping case which means that the recursion will stop when the base case/ base condition evaluates to true. The recursive case is when the function keeps calling itself so the recursive function keepsexecuting until the base case becomes true.

Here the base case is if n == 1:  So the recursive function calling itself until the value of n becomes 1.  

Recursive case is:

       return term(n) + summation(n - 1, term)

For the above example with n= 5 and term = x:2**x the recursions starts from n and adds all the terms of the series one by one and the value of n keeps decrementing by 1 at every recursive call.

When the value of n is equal to 1 the base case gets true and the recursion ends and the result of the sum is displayed in output.

This is how the summation() function works for the above function call:

2^1 + 2^2 + 2^3 + 2^4 + 2^5

n is 5 So this term function is called recursively 5 times and at every recursive call its value decreases by 1. Here the term function is used to compute 2 raise to power n. So in first recursive call the 2 raise to the power 5 is computed, then 5 is decremented and then in second recursive call to summation(), 2 raise to the power 4 is calculated, in third recursive call  to summation(), 2 raise to the power 3 is calculated, in fourth recursive call  to summation(), 2 raise to the power 2 is calculated, in fifth recursive call  to summation(), 2 raise to the power 1 is calculated, then the base condition is reached as n==1. So the recursion stops and the sum of the above computed power function results is returned which is 62.

2^1 + 2^2 + 2^3 + 2^4 + 2^5 = 62

The screen shot of recursive function along with the output of explained examples is attached.

You might be interested in
A large plate is fabricated from a steel alloy that has a plane strain fracture toughness of 55 MPa √m (50 ksi √in.). If, during
astra-53 [7]

Answer:

0.024 m = 24.07 mm

Explanation:

1) Notation

\sigma_c = tensile stress = 200 Mpa

K = plane strain fracture toughness= 55 Mpa\sqrt{m}

\lambda= length of a surface crack (Variable of interest)

2) Definition and Formulas

The Tensile strength is the ability of a material to withstand a pulling force. It is customarily measured in units (F/A), like the pressure. Is an important concept in engineering, especially in the fields of materials and structural engineering.

By definition we have the following formula for the tensile stress:

\sigma_c=\frac{K}{Y\sqrt{\pi\lambda}}   (1)

We are interested on the minimum length of a surface that will lead to a fracture, so we need to solve for \lambda

Multiplying both sides of equation (1) by Y\sqrt{\pi\lambda}

\sigma_c Y\sqrt{\pi\lambda}=K   (2)

Sequaring both sides of equation (2):

(\sigma_c Y\sqrt{\pi\lambda})^2=(K)^2  

\sigma^2_c Y^2 \pi\lambda=K^2   (3)

Dividing both sides by \sigma^2_c Y^2 \pi we got:

\lambda=\frac{1}{\pi}[\frac{K}{Y\sigma_c}]^2   (4)

Replacing the values into equation (4) we got:

\lambda=\frac{1}{\pi}[\frac{55 Mpa\sqrt{m}}{1.0(200Mpa)}]^2 =0.02407m

3) Final solution

So the minimum length of a surface crack that will lead to fracture, would be 24.07 mm or more.

7 0
3 years ago
An ideal gas initially at 300 K and 1 bar undergoes a three-step mechanically reversible cycle in a closed system. In step 12, p
Veseljchak [2.6K]

Answer:

Ts =Ta E)- 300(

569.5 K

5

Q12-W12 = -4014.26

Mol

AU2s = Q23= 5601.55

Mol

AUs¡ = Ws¡ = -5601.55

Explanation:

A clear details for the question is also attached.

(b) The P,V and T for state 1,2 and 3

P =1 bar Ti = 300 K and Vi from ideal gas Vi=

10

24.9x10 m

=

P-5 bar

Due to step 12 is isothermal: T1 = T2= 300 K and

VVi24.9 x 10x-4.9 x 10-3 *

The values at 3 calclated by Uing step 3l Adiabatic process

B-P ()

Since step 23 is Isochoric: Va =Vs= 4.99 m* and 7=

14

Ps-1x(4.99 x 103

P-1x(29x 10)

9.49 barr

And Ts =Ta E)- 300(

569.5 K

5

(c) For step 12: Isothermal, Since AT = 0 then AH12 = AU12 = 0 and

Work done for Isotermal process define as

8.314 x 300 In =4014.26

Wi2= RTi ln

mol

And fromn first law of thermodynamic

AU12= W12 +Q12

Q12-W12 = -4014.26

Mol

F'or step 23 Isochoric: AV = 0 Since volume change is zero W23= 0 and

Alls = Cp(L3-12)=5 x 8.311 (569.5 - 300) = 7812.18-

AU23= C (13-72) =5 x 8.314 (569.3 - 300) = 5601.53

Inol

Now from first law of thermodynamic the Q23

AU2s = Q23= 5601.55

Mol

For step 3-1 Adiabatic: Since in this process no heat transfer occur Q31= 0

and

AH

C,(T -Ts)=x 8.314 (300- 569.5)= -7842.18

mol

AU=C, (T¡-T)= x 8.314 (300

-5601.55

569.5)

mol

Now from first law of thermodynamie the Ws1

J

mol

AUs¡ = Ws¡ = -5601.55

3 0
3 years ago
It is said that Archimedes discovered his principle during a bath while thinking about how he could determine if King Hiero’s cr
arlik [135]

Answer: The crown is not made of pure gold.

Explanation:

Archimedes discovered that any solid, of any shape, when submerged in a liquid receives an upward force, equal to the weight of the volume of the liquid removed by the solid, which is equal to the solid volume.

So, if any body is weighed in air, the normal force will be equal to the gravity force (which we call weight) which can be expressed as follows:

Fg = m g = δ V g = 34.7 N

When submerged in water, the normal force is equal to the difference between the actual weight, and the upward force due to Archimedes' principle, called buoyant force, as follows:

Fn = Fg - Ep = δx. V. g - δH20 . V. g = 31.5 N

Dividing Fg between Fn, and simplifying common terms, we have:

δx / (δx - δh20) = 34.7 / 31.5 = 1.10

Solving for δx, we get the following value:

δx = 11,000 Kg/m3, less dense than pure gold, so we can conclude that the crown was not made of pure gold.

3 0
3 years ago
Describe the Optical Fiber Network( i need 2 paragraphs, but give me about 5 sentences or like 3)
frez [133]

Answer: Fiber Optic Network Fiber-optic networks have been used for decades to transmit large volumes of traffic across the country. The economics of fiber networks have only recently allowed for connecting the fiber directly to the home, creating a fiber-to-the-home (FTTH) network.

Explanation:

6 0
3 years ago
Read 2 more answers
For arwa and yeahahhahahhhhhhhhhhhhh
Setler79 [48]
Chicken nugget baby sauce
3 0
3 years ago
Read 2 more answers
Other questions:
  • An excavation is at risk for cave-in and water accumulation because of the excess soil that has accumulated. What type of excava
    12·1 answer
  • Amanda and Tyler opened a business that specializes in shipping liquids, such as milk, juice, and water, in cylindrical containe
    5·1 answer
  • [4 points] Does the green LED emit light when you connect the banana plug wires across it? What does that say about the threshol
    13·1 answer
  • You want to plate a steel part having a surface area of 160 with a 0.002--thick layer of lead. The atomic mass of lead is 207.19
    15·1 answer
  • Problem 89:A given load is driven by a 480 V six-pole 150 hp three-phase synchronous motor with the following load and motor dat
    11·1 answer
  • Suppose there is a mobile application that can run in two modes: Lazy or Eager. In Lazy Mode, the execution time is 3.333 second
    11·1 answer
  • _____ are used to control the flow of electricity in a circuit.
    8·2 answers
  • What is the fastest motorcycle in the world ?
    7·2 answers
  • which acpi power state allows a system to start where it left off, but all other components are turned off? sleeping mechanical
    13·1 answer
  • How old are legos? Who created them? Why did they create them?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!