Question

Develop an alternative formulation for calculating the polynomial expression that avoids the need for repeated power calculation and reduces the risk of numerical instability

(iv) In calculating the value of a polynomial func


0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <bits/stdc++.h>
#define max 10
using namespace std;

int main()
{
int ar[max];
int i, num, power;
float x, result;

cout<<"Enter the order of the polynomial \n";
cin>>num;
cout<<"Enter the value of x \n";
cin>> x;
cout<<"Enter " <<num + 1<< "coefficients \n";
for (i = 0; i <= num; i++)
{
cin>>ar[i];
}
result = ar[0];
for (i = 1; i <= num; i++)
{
result = result * x + ar[i];
}
power = num;

cout<<"Polynomial is: \n";
for (i = 0; i <= num; i++)
{
if (power < 0)
{
break;
}

if (ar[i] > 0)
cout<<" + ";
else if (ar[i] < 0)
cout<<" - ";
else
cout<<" ";
cout<<abs(ar[i])<<"x^" <<(power--);
}
cout<<"\n Value of the polynomial = "<<result;
}

===================================================================

akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
Enter the order of the polynomial
2
Enter the value of x
2
Enter 3 coefficients
3
2
6
Given polynomial is:
+ 3x^2 + 2x^1 + 6x^0
Value of the polynomial = 22

Add a comment
Know the answer?
Add Answer to:
Develop an alternative formulation for calculating the polynomial expression that avoids the need for repeated power...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT