使用c++实现表达式计算
School of Mathematical Sciences
MATH4063.G14SCC Scientific Computing and C++
Submission Date: Monday 4th November 2019, 11pm Assessed Coursework 1 – Solution
Template
Your results to the assessed coursework must be submitted using this template. Please cut and paste
the subsequent output into the correct parts of this file. Once this template has been completed,
you must then create a pdf file for submission. Under Windows 10/Windows 7 use Texmaker 5; this
may be accessed as follows:
Start > UoN Applications > (UoN) Texmaker 5
Open this file under File; to build the pdf file, click the arrow next to Quick Build; this will then
generate the file course work1 submission.pdf.
A single zip or tar file containing your solution should be submitted through the module
webpage on Moodle. NOTE: All parameters and values (such as polynomial degrees etc.) should
be set within your codes: do NOT use inputs such as obtained with std::cin.
File checklist:
course work1 submission.pdf
newtonhorner.cpp containing the functions horner and newton
chebyshev.cpp containing the functions chebeval, chebsum, and chebcoef
lagrange.cpp containing the function lagrange
q1a.cpp
q1b.cpp
q1c.cpp
q2a.cpp
q2b.cpp
q3.cpp
q3b.cpp
runge.pdf
1(a) Enter your output here:
%%%%%%%%%%%%%%%%%%% Output for Example 1a %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1(b) Enter your output here:
%%%%%%%%%%%%%%%%%%%%%%%%%% Example 1: p(x)=x^2-1 %%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%% Example 2: p(x)=x^5+x^4-9x^3-x^2+20x-12 %%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%% computed root when nmax = 5 %%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%% computed root when nmax = 10 %%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1(c) Enter your output here:
%%%%%%%%%%%% computed roots for p(x)=x^5+x^4-9x^3-x^2+20x-12 %%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2(a) Enter your output here:
%%%%%%%%%%%%% value of P_2(0.5), P_3(-0.5), and P_9(0.7) %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2(b) Enter your output here:
%%%%%%%%%%%%%%%%%%% S_10(x) for x=-1, -0.5, 0, 0.5, 1 %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3(a) Enter your output here:
%%%%%%%%%%%% f(x)=x^4+x, n=2 interpolation error at x=1/6 %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%% f(x)=x^4+x, n=4 interpolation error at x=1/6 %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3(b) Enter your output here:
%%%%%%%%%%%% f(x)=x^4+x, n=2 interpolation error at x=1/6 %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
%%%%%%%%%%%%%%%%%%%%%%%%%%% f(x)=1/(1+16 x^2) %%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% n=2 uniform and Chebyshev interpolation error at x=1/6 %%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% n=10 uniform and Chebyshev interpolation error at x=1/6 %%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% n=2 uniform and Chebyshev interpolation error at x=.9 %%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% n=10 uniform and Chebyshev interpolation error at x=.9 %%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% plot of uniform interpolant, Chebyshev interpolant, and %%%%%%
To insert here your plot, de-comment the below line
3(c) Enter your output here:
%%%%%%%%%%%%%%%%%%%%%%%%%%% f(x)=1/(1+16 x^2) %%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%% n=2 coefficients of the Chebyshev sum %%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%% n=2 Chebyshev interpolation error at x=.9 %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3