Question

In: Computer Science

A third degree polynomial equation (a cubic equation) is of the form p(x) = c3x 3...

A third degree polynomial equation (a cubic equation) is of the form p(x) = c3x 3 + c2x 2 + c1x + c0, where x and the four coefficients are integers for this exercise. Suppose the values of the coefficients c0, c1, c2, and c3have been loaded into registers $t0, $t1, $t2, and $t3, respectively. Suppose the value of x is in $t7.

Write the MIPS32 instructions that would evaluate this polynomial, placing the result in $t9.

Solutions

Expert Solution

# A third degree polynomial equation is p(x) = c3x 3 + c2x 2 + c1x + c0,

       .text
        .globl main

main:
        lw   $t0,c0          # get c0 -- Load word of c0 to the register of t0
        lw   $t1,c1          # get c1 -- Load word of c1 to the register of t1
        lw   $t2,c2          # get c2 -- Load word of c2 to the register of t2
        lw   $t3,c3          # get c3 -- Load word of c3 to the register of t3
       lw   $t7,x          # get x -- Load word of x to the register of t7

        mult $t7,$t7        # x2 -- Multiply x => x*x=x2
        mflo $t4             # $t4 = x2 -- move x2 to $t4
        nop                   # No operation performed
      
       mult $t4,$t7       # x3 -- Multiply x => x2*x=x3
        mflo $t5            # $t5 = x3 -- move x3 to $t5
        nop
      
       mult $t1,$t7        # c1x -- Multiply c1 by x => c1*x=c1x
        mflo $t6             # $t6 = c1x -- move c1x to $t6
        nop

       mult $t2,$t4        # c2x2 -- Multiply c2 by x2 => c2*x2=c2x2
        mflo $t8             # $t8 = c2x2 -- move c2x2 to $t8
        nop

       mult $t3,$t5        # c3x3 -- Multiply c3 by x3 => c3*x3=c3x3
        mflo $t9             # $t9 = c3x3
        nop
     
        addu $t9,$t9,$t8    # $t9 = c3x3 + c2x2 -- add c3x3 and c2x2. Hence c3x3+c2x2 and load it to $t9 register
        addu $t9,$t9,$t6    # $t9 = c3x3 + c2x2 + c1x
       addu $t9,$t9,$t0    # $t9 = c3x3 + c2x2 + c1x + c0
      
        sw   $t9,value      # p(x) = c3x3 + c2x2 + c1x + c0 -- polynomial


Related Solutions

Given: Polynomial P(x) of degree 6 Given: x=3 is a zero for the Polynomial above List...
Given: Polynomial P(x) of degree 6 Given: x=3 is a zero for the Polynomial above List all combinations of real and complex zeros, but do not consider multiplicity for the zeros.
Find a third-degree-polynomial model of salinity  as a function of time . Use the general form of...
Find a third-degree-polynomial model of salinity  as a function of time . Use the general form of a polynomial in the box on page 114 of our textbook. Hint: proceed much as you did for the quadratic model, and look ahead to the next paragraph. Explain why it’s possible to find more than one third-degree-polynomial model that fits the data perfectly. Use your third-degree-polynomial model to predict the salinity at . Make a large graph of your third-degree-polynomial model, at least...
Let P(x) be a polynomial of degree n and A = [an , an-1,.... ] Write...
Let P(x) be a polynomial of degree n and A = [an , an-1,.... ] Write a function integral(A, X1, X2) that takes 3 inputs A, X0 and X1 A as stated above X1 and X2 be any real number, where X1 is the lower limit of the integral and X2 is the upper limit of the integral. Please write this code in Python.
Let P(x) be a polynomial of degree n and A = [an , an-1,.... ] Write...
Let P(x) be a polynomial of degree n and A = [an , an-1,.... ] Write a function integral(A, X1, X2) that takes 3 inputs A, X0 and X1 A as stated above X1 and X2 be any real number, where X1 is the lower limit of the integral and X2 is the upper limit of the integral. Please write this code in Python. DONT use any inbuilt function, instead use looping in Python to solve the question. You should...
Solve the 4 degree polynomial equation.
Solve the 4 degree polynomial equation \( x^4 − 2x^3 + 4x^2+ 6x − 21 = 0 \), given that the sum of two its roots is zero.
2. a) Find Ts(x), the third degree Taylor polynomial about x -0, for the function e2...
2. a) Find Ts(x), the third degree Taylor polynomial about x -0, for the function e2 b) Find a bound for the error in the interval [0, 1/2] 3. The following data is If all third order differences (not divided differences) are 2, determine the coefficient of x in P(x). prepared for a polynomial P of unknown degree P(x) 2 1 4 I need help with both. Thank you.
Task 3: a) A second-degree polynomial in x is given by the expression = + +...
Task 3: a) A second-degree polynomial in x is given by the expression = + + , where a, b, and c are known numbers and a is not equal to 0. Write a C function named polyTwo (a,b,c,x) that computes and returns the value of a second-degree polynomial for any passed values of a, b, c, and x. b) Include the function written in part a in a working program. Make sure your function is called from main() and...
5a. Write the equation of the polynomial with leading coefficient 3 that has degree 4, with...
5a. Write the equation of the polynomial with leading coefficient 3 that has degree 4, with x-intercepts at -2 and 1, both having a multiplicity of 2. b. Write the equation of the polynomial which goes through the following points. (-2,0),(-1,0),(5,0), and (0,10). c. (1+i) is a zero of f(x)=x^4 - 2x^3 - x^2+ 6x - 6. Find the other zeros Please show all the work. Expert and correct answers only.
Let x0< x1< x2. Show that there is a unique polynomial P(x) of degree at most...
Let x0< x1< x2. Show that there is a unique polynomial P(x) of degree at most 3 such that P(xj) =f(xj) j= 0,1,2, and P′(x1) =f′(x1) Give an explicit formula for P(x). maybe this is a Hint using the Hermit Polynomial: P(x) = a0 +a1(x-x0)+a2(x-x0)^2+a3(x-x0)^2(x-x1)
If p(z) is a polynomial of degree n and that if α is a root of...
If p(z) is a polynomial of degree n and that if α is a root of p(z) = 0, then p(z) factors as p(z) = (z−α)q(z) where q(z) has degree (n − 1). Use this and induction to show that a polynomial of degree n has at most n roots.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT