subject
Engineering, 13.03.2020 19:52 pearlielb

In pyhton!

We could, in principle, represent a polynomial as a list. For instance, we could write

1+2xโˆ’3x2+2x41+2xโˆ’3x2+2x4

as

[ 1,2,-3,0,2
where the ith index corresponds to xixi . If we wrote a polynomial this way, we would also like an easy way to evaluate that polynomial for a specified value of xx ; i. e., for x=1.5x=1.5 ,

1+2ร—1.5โˆ’3ร—1.52+2ร—1.54=7.3751+2ร—1.5โˆ’ 3ร—1.52+2ร—1.54=7.375

Compose a function polyeval( coefs, x ) which accepts a list of polynomial coefficients from lowest to highest order (as above) and a value x at which to evaluate the polynomial, and returns a float corresponding to the value of the polynomial evaluated at x.

A good way to start your code would be:

def polyeval( coefs, x ):
value = ??? # an accumulator pattern
# with some kind of loop here
return value
For instance, polyeval( [ 1,1,0,1 ],1 ) (1+x+x31+x+x3 for x=1x=1 ) should return 3.0. polyeval( [ 0,1,0,-2,1 ],-1 ) (xโˆ’2x3+x4xโˆ’2x3+x4 for x=โˆ’1x=โˆ’1 ) should return 2.0.

ansver
Answers: 1

Another question on Engineering

question
Engineering, 04.07.2019 19:10
Starting wih an energy balance on a rectangular volume element, derive the one- dimensional transient heat conduction equation for a plane wall with constant thermal conductivity and no heat generation.
Answers: 1
question
Engineering, 04.07.2019 19:10
A)-explain briefly the importance of standards in engineering design. b)- what is patent? c)-explain the relationship between these standards: b.s. and b.s.en d)- in engineering design concepts, types of loads and how they act are important factors. explain.
Answers: 3
question
Engineering, 04.07.2019 19:20
Determine (a) the maximum thermal efficiency of reversible power cycles operating between a hot reservoir at 1000ยฐc and a cold reservoir at 200ยฐc and (b) the maximum cops for reversible refrigeration and heat pump cycies, respectively, between 28ยฐc and 14ยฐc.
Answers: 1
question
Engineering, 06.07.2019 04:10
Amixture of gases consists of 0.4 kg of oxygen, 0.7 kg of carbon dioxide, and 0.2 kg of helium this mixture is maintained at 100 kpa and 27ยฐc. determine: (a) the apparent molecular weight of this mixture the volume it occupies (b) the partial volume of the oxygen, and (c) (d) the partial pressure of the helium
Answers: 1
You know the right answer?
In pyhton!

We could, in principle, represent a polynomial as a list. For instance, we co...
Questions
question
Mathematics, 14.09.2021 14:50
question
Mathematics, 14.09.2021 14:50
question
Mathematics, 14.09.2021 14:50
question
Biology, 14.09.2021 14:50
question
Mathematics, 14.09.2021 14:50
question
Mathematics, 14.09.2021 14:50
question
Mathematics, 14.09.2021 14:50
Questions on the website: 13722360