1. Homepage
  2. Programming
  3. CS100 Homework 10 Polynomial Computation

CS100 Homework 10 Polynomial Computation

Engage in a Conversation
CS100Polynomial ComputationC++

CS100 Homework 10 (Spring, 2022) CourseNana.COM

Deadline: 2022-06-21 23:59:59 CourseNana.COM

Late submission will open for 24 hours after the deadline, with -50% point deduction. CourseNana.COM


CourseNana.COM

Polynomial Computation CourseNana.COM

You have two tasks in this problem. First you need to implement a polynomial class which supports some basic operations. Then you need to parse an expression that contains multiple polynomial and evaluate it at an arbitray point x 2 R. CourseNana.COM


CourseNana.COM

Polynomial Class CourseNana.COM

We use a list of coefficients to represent a polynomial. For example, the polynomial 1 + 2x + 3x4 is represented by [1,2,0,0,3], and stored as a private variable m coeffs of type std::vector<double>. CourseNana.COM


CourseNana.COM

You need to implement all the member functions in the Polynomial class. After implementing Matrix and Array in the previous homework, you should be quite familiar with those constructors and operators  by now. Don't forget to use std::move for rvalue reference in constructors. CourseNana.COM


CourseNana.COM

The class also supports reading coefficients from a file and get initialized. The data/ folder contains the data that we need. Each file p*.txt contains a line of spaced polynomial coefficients, with the first one being the coefficient of the zero degree term. For example the line -1 0 2 indicates the polynomial ?1 + 2x2. CourseNana.COM


CourseNana.COM

Please read the comments in include/polynomial.hpp for more details. You need to implement all the member functions in src/polynomial.cpp. CourseNana.COM


CourseNana.COM


CourseNana.COM

Reverse Polish Notation CourseNana.COM

In this task, we will use Reverse Polish Notation (also known as post x notation) to represent expressions in which the operator is placed after the arguments begin operated on. For example, the expression "(3 + 4) * 5" is written "3 4 + 5 *" in reverse polish notation. In comparision, reverse Polish notation lead to faster calculation. The reason is that reverse Polish calculators do not need expressions to be parenthesized, so fewer operations need to be entered. CourseNana.COM


CourseNana.COM

In practice RPN can be conveniently evaluated using a stack structure. Reading the expression from left to right, the following operations are performed: CourseNana.COM

1. If a value appears next in the expression, push this value onto the stack. CourseNana.COM

2. If an operator appears next, pop two items from the top of the stack and push the result of the operation onto the stack. CourseNana.COM

The procedure of evaluating a RPN expression 3 4 + 5   is as follows: CourseNana.COM

1. Push 3 onto the stack. CourseNana.COM

2. Push 4 onto the stack. CourseNana.COM

3. Pop 4 and 3 from the stack, compute 3 + 4 and push the result onto the stack. CourseNana.COM

4. Push 5 onto the stack. CourseNana.COM

5. Pop 5 and 7 from the stack, compute 7   5 and push the result onto the stack. CourseNana.COM

6. The final result is 35 CourseNana.COM

In our case, an example of polynomial expression is p1 p2 + p3   where p1; p2; p3 stands for different polynomials. Each operator and operand is separated by a space. It is guaranteed that the expression is valid and only contains supported operations for polynomial (addition, subtraction and multiplication). CourseNana.COM

You may use std::stack for stack operations. CourseNana.COM


CourseNana.COM

Evaluation CourseNana.COM

We want to evaluate a function of polynomials at an arbitrary point. For example, we want to evaluate p1 p2 + p3   at point x = 1:5. One possible way could be CourseNana.COM

1. Read the coefficients of polynomials from file. CourseNana.COM

2. Parse the function string p1 p2 + p3   and generate a new Polynomial. CourseNana.COM

3. Evaluate the new polynomial at given point. CourseNana.COM


CourseNana.COM

The main drawback of the approach above is that it seems difficult, if not impossible, to do polynomial division for the Polynomial class or on the polynomial ring. CourseNana.COM

As a remedy, we promote the use of lambda function. For that purpose you have to write the lambda functions for addition, multiplication etc. Then you can parse the function string, compute and store the generated function for further evaluation. CourseNana.COM


CourseNana.COM

In this task, you need to implement the two functions compute polynomial and compute lambda. You need to implement the first solution in compute polynomial which returns a Polynomial instance. You need to use lambda function in compute lambda for polynomial operations and return a function of type std::function<double(double)>. Please read the comments in include/polynomial parser.hpp for details. You need to put your implementation in src/polynomial parser.cpp. CourseNana.COM


CourseNana.COM

Testing CourseNana.COM

We have also provided you some test code. Under folder test/ you will see three files for test. The test can be performed by CTest in CMake. The expected output is written in test/CMakeLists.txt. You can run the test by running cmake test after you have successfully built your code. CourseNana.COM

  CourseNana.COM

You can add more tests by yourself by modifying test/CMakeLists.txt and adding more data in data/. Make sure you have correctly set the expected output or you may waste lots of time for debugging. CourseNana.COM


CourseNana.COM

Submission Guideline CourseNana.COM

We will use Autolab to judge your code. You need to sumbit a .tar file which directly contains polynomial.cpp and polynomial parser.cpp. DO NOT add any other files or folders. The structure of your submission should be like hw10.tar CourseNana.COM

- polynomial.cpp CourseNana.COM

- polynomial parser.cpp CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
CS100代写,Polynomial Computation代写,C++代写,CS100代编,Polynomial Computation代编,C++代编,CS100代考,Polynomial Computation代考,C++代考,CS100help,Polynomial Computationhelp,C++help,CS100作业代写,Polynomial Computation作业代写,C++作业代写,CS100编程代写,Polynomial Computation编程代写,C++编程代写,CS100programming help,Polynomial Computationprogramming help,C++programming help,CS100assignment help,Polynomial Computationassignment help,C++assignment help,CS100solution,Polynomial Computationsolution,C++solution,