Cs1325- write a program to evaluate any function of order 5


Introduction to Programming Assignment- Basic C

Introduction

In this assignment you will write small C programs. Each C program should be submitted as a standard C source code file. You can submit your files separately or zipped together into one file.

Please note that the computer program should comply with the commenting and formatting rules as has been done in class. For example, there should be a header for the whole program that gives the author's name, class name, date, and description. End braces should be commented, and there are alignment and indenting requirements as discussed. Please ask if you have any questions.

Program #1

Write a program for each case (a to c). Each program will ask the user for an integer number n and a character ch. The output generated depends on the value of n and the character ch.

For example, say that n = 5 and ch = ‘*':
(5 points) Program 1.a) will display

*
***
*****
*******
*********
Program 1.b) will display:

*
* *
* * *
* * * *
* * * * *

Notice: the number of spaces between each ‘*' is increasing at each row.

Program 1.c) will display 1* 2* 3* 4* 5*

2* 3* 4* 5* 1*
3* 4* 5* 1* 2*
4* 5* 1* 2* 3*
5* 1* 2* 3* 4*

Program #2

Write a program to evaluate any function of order 5 or less at a given interval [xmin, xmax], and display a table with the values of x, and f(x).

INPUT: The program will ask the user to enter

a) The function's order f_order.

• If the order is greater than 5 or smaller than 1, an error message should be displayed and the program ends,
• Otherwise, the program will ask for the respective coefficients.

b) The values for xmin and xmax

• If the value for xmax is smaller or equal to xmin, an error messages should be displayed and the program will end.

Assume that f(x) is defined as f(x) = ax5 + bx4 + cx3 + dx2 + ex + f.

If the f_order is:

• 5, then the program will ask for coefficients a, b, c, d, e and f;
• 4, then the program will ask for coefficients b, c, d, e and f;
• 3, then the program will ask for coefficients c, d, e and f;
• 2, then the program will ask for coefficients d, e and f;
• 1, then the program will ask for coefficients e and f;

OUTPUT:

The output is formatted as a table. The first column will display the values of x, and the second column the values of f(x). The first row should always have the value xmin for x, and f(xmin) for f(x). Last row should always have the value xmax for x, and f(xmax) for f(x).

The table will look like:

x f(x)
-----------|-------------------
xmin | f(xmin)
xmin +dx | f(xmin+dx)
xmin +2dx | f(xmin+2dx)
xmin +3dx | f(xmin+3dx)
xmin +4dx | f(xmin+4dx)
. |
. |
xmax | f(xmax)
------------------------------

Where

• xmin is the value entered by the user, and
• f(xmin) is the result of evaluating the function when x=xmin
• dx is the increment size, and is defined by ???? = (???????? - ????????)/10

Use 2 decimals for f(x) values.

Table formatting: 10 points
Function evaluation: 20 points

Include a report in a Word file that shows

a) List all the variables, constants(literals, symbolic and named) in your program 2). (5 points)

*Optional [Extra Points]:

- Include in the word file, plots of f(x) in the range [-13,13] for each valid value of f_order (10 points). You pick the coefficients for each case.

If you do not have access to MATLAB you can also use OCTAVE or SciLab.

You are allowed to use the function float pow( float, int), found in , to calculate the powers of x.

Topics covered: Basic C, Expression evaluation, operators, flow control statements (loops, switch-case, if-else, etc) and MATLAB as optionals.

Attachment:- Basic_C.pdf

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: Cs1325- write a program to evaluate any function of order 5
Reference No:- TGS02192448

Expected delivery within 24 Hours