Question

In: Advanced Math

1. (2 pts each) Consider the following algorithm: procedure polynomial(c, a0,a1,…an: real numbers) power≔1 y≔a0for i=1...

1. (2 pts each) Consider the following algorithm:

procedure polynomial(c, a0,a1,…an: real numbers)
power≔1
y≔a0
for i=1 to n
  
power≔power*c
y≔y+ai*power
return y
(Note: y=ancn + an-1 cn-1 +. . . + a1C +a0 so the final value of y is the value of the polynomial at x=c)

a. Use the algorithm to calculate f(3), where f(x)=2x2+3x+1 at x=3. Show the steps of working through the algorithm – don’t just plug 3 in for x in f(x).

b. How many multiplications and additions are needed to evaluate a polynomial of degree n at x=c?

Solutions

Expert Solution

a)

We have to calculate f(x) = 2x2 + 3x +1 at x = 3.

So here we get, a0 = 1 , a1 = 3 , a2 = 2 & c = 3.

From the algorithm;

Step 1 (Initialization) :

Here we initialize the values as follows :

Step 2 (Iteration ( i = 1, 2)) :

In each iterative steps, the value of "power" and "y" are updated. The new value of "power" is assigned as the previous value of power multiplied with "c" and the value of "y" is assigned to be "yprevious+ ai*power".

For i = 1 ;

For i = 2 ;

Step 3 :

return y

i.e. return 28

Therefore, f(3)=28, where f(x)=2x2+3x+1 at x=3.

b)

Observe the algorithm only performs addition and multiplication in step 2 (Iteration) i.e.

power≔power*c
y≔y+ai*power

Here we see, there are 2 muliplication "power*c" and "ai*power" and 1 addition "y≔y+ai*power" per each iteration.

Since there can be "n" number of iterations for a n-degree polynomial as "i" can take values from 1 to n,

The number of multiplication performed = 2n

The number of addition performed =n


Related Solutions

write an algorithm program using python or C++ where a0=1, a1=2 an=an-1*an-2, find an ,also a5=?
write an algorithm program using python or C++ where a0=1, a1=2 an=an-1*an-2, find an ,also a5=?
2. Write the hexadecimal numbers in the registers of $a0, $a1, $a2, $a3 after the following...
2. Write the hexadecimal numbers in the registers of $a0, $a1, $a2, $a3 after the following codes running: ori $a0, $0, 11 ori $a1, $0, 19 addi $a1, $a1, -7 slt $t2, $a1, $a0 beq $t2, $0, label addi $a2, $a1, 0 sub $a3, $a1,$a0 j end_1 label: ori $a2, $a0, 0 add $a3, $a1, $a0 end_1: xor $t2, $a1, $a0 *Values in $a0, $a1, $a2, $a3 after the above instructions are executed.
1. Define the elements of the following equation: P = a0 ‒ a1 × Qd. 2....
1. Define the elements of the following equation: P = a0 ‒ a1 × Qd. 2. Given P = $150 ‒ 0.005 × Qd as the demand for a professional sports team: a. If P = $60, what is Qd? b. If P = $40, what is Qd? 3. Imagine these two possible changes from the demand curve listed in Question 2: a. P = $175 ‒ 0.005 × Qd b. P = $125 ‒ 0.005 × Qd For each,...
Consider the parabolas y=x^2 and y=a(x-b)^2+c, where a,b,c are all real numbers (a) Derive an equation...
Consider the parabolas y=x^2 and y=a(x-b)^2+c, where a,b,c are all real numbers (a) Derive an equation for a line tangent to both of these parabolas (show all steps with a proof, assuming that such a line exists) (b) Assume that the doubly-tangent line has an equation y+Ax+B. Find an example of values of a,b,c (other than the ones given here) such that A,B ∈ Z
Solve the following recurrence relation (A) an = 3an-1 + 4an-2 a0 =1, a1 = 1
  Solve the following recurrence relation   (A) an = 3an-1 + 4an-2 a0 =1, a1 = 1   (B) an = 2an-1 - an-2, a0 = 1, a2= 2
Consider the following algorithm, which takes as input a sequence of ?n integers ?1,?2,…,??a1,a2,…,an and produces...
Consider the following algorithm, which takes as input a sequence of ?n integers ?1,?2,…,??a1,a2,…,an and produces as output a matrix ?={???}M={mij} where ???mij is the minim term in the sequence of integers ??,??+1,…,??ai,ai+1,…,aj for ?≥?j≥i and ???=0mij=0 otherwise. for i := 1 to n for j := 1+1 to n for k:= i+1 to j m[i][j] := min(m[i][j], a[k]) end for end for end for return m a.) Show that this algorithm uses ?(?3)O(n3) comparisons to compute the matrix M....
Consider the following non-homogeneous linear recurrence: an =−an-1 +6an-2+125(8+1)·(n+1)·2n a0 = 0 a1 = 0 (b)...
Consider the following non-homogeneous linear recurrence: an =−an-1 +6an-2+125(8+1)·(n+1)·2n a0 = 0 a1 = 0 (b) Find the solution an(h) to the associated homogeneous linear recurrence. n (c) Find a particular solution anp to the non-homogeneous linear recurrence. (d) Find the general solution to the non-homogeneous linear recurrence.
2. Consider the simplified national income model:     Y = C + I…………(1)                            Where Y...
2. Consider the simplified national income model:     Y = C + I…………(1)                            Where Y is national income, C is consumption, and I is investment. Consumption is determined by a behavioral equation, which in this problem takes the form      C= 3000+ .75 Y……..(2) Where Y and C are endogenous variables and Investment is exogenous, and, initially we assume I =1000……………….(3) (2-a) Determine the equilibrium level of national income (Y) and consumption (C) by using the matrix (linear) algebra...
Consider an economy described by the following equations: Y = C + I + G Y...
Consider an economy described by the following equations: Y = C + I + G Y = 5000 G = 1000 T = 1000 C = 250 + .75 (Y - T) I = 1000 - 50r a. In this economy, compute private saving, public saving, and national saving b. Find the equilibrium interest rate c. Now suppose that G rises to 1250. Compute private saving, public saving, and national saving d. Find the new equilibrium interest rate.
Consider an economy described by the following equations Y = C + I + G Y=4,000...
Consider an economy described by the following equations Y = C + I + G Y=4,000 G= 1,000 T=800 C =400 + 0.75(Y–T) I = 1,000–50r(a) For this economy, compute the following [1.5 Points each; 6 Points total]1. Private Savings2. Public Savings3. National Savings4. Equilibrium interest rate (b) Is this economy running a budget surplus, budget deficit or a balanced budget? Explain. [2 Points] (c) Suppose that Congress decides to reduce government spending. The new level of government spending is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT