Assignment VI

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Assignment 6

Write a program that asks for the degree of a

Enter Degree of Polynomial: 3

polynomial and then prompts for each coefficient

Enter Coefficient of x^0:

as shown.

Enter Coefficient of x^1:

The program calculates coefficients of f(x) from the coefficients

Enter Coefficient of x^2:

of f(x).

Enter Coefficient of x^3:

The program prints out the expression for f(x) and


f(x) on the screen as shown.

Polynomial is:
f(x) = 1 + 1*x^1 + 1*x^2 + 1*x^3

The program then prompts for the starting and end point of
a range of x values together with a step.

Derivative is:
f'(x) = 1 + 2*x^1 + 3*x^2

The program produces a neatly formatted


table of x values and polynomial values. Use only cout, cin and

Enter x0,x1,Step:

0.0 2.0 0.2

characters (such as |) to format.


NOTE:The polynomial can be of ANY degree and the range can be

====================================
x

0.2

1.248

1.52

0.4

1.624

2.28

0.6

2.176

3.28

0.8

2.952

4.52

1.2

5.368

7.72

Also, write functions as needed:

1.4

7.104

9.68

For example, write a function which accepts a

1.6

9.256

11.88

vector of coefficients, an integer which is the length of

1.8

11.872 |

14.32

that vector and a value for x and returns the value of

15

17

the polynomial at that value of x.

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

Write another function which prints out the expression for a polynomial

RMS energy of f(x) = 7.17029

of ANY size.
The program then calculates and prints the RMS energy of f as follows:
Take the mean of the values of f(x_i) squared. The
square root of the value of the mean above is the RMS energy. You will
need to store the values of f(x) for x in the range above.

Use new and delete: For example, store the coefficients


of f(x) and f(x) in dynamically allocated 1d arrays.

given the coefficients and the degree.

f'

You might also like