Programming language is C++. Show code and an example of the output when PuTTY w
ID: 3787923 • Letter: P
Question
Programming language is C++. Show code and an example of the output when PuTTY when done.
Write your own cube root function named double my_cbrt_l(double n) using the following pade approximant: 3 squareroot n almostequalto 101.639 n^2+ 207.853 n+39.7541/-n^3+42.945 n^2 + 215.165 n+ 82.1357 and then write a main which prints n, cbrt(n), and my_cbrt_l(n) for n = pi times 10 to the k^th power for k = -100, -10, -1, 0, 1, 10, and 100. Use this code: for(auto k: {-100, -10. -1, 0, 1, 10, 100}){n = M_PI * pow(10.0, k);//cout goes here} Name your program hw2pr2.cpp.Explanation / Answer
Here is the code for you:
double my_cbrt_2(double n)
{
return (101.639 * n * n + 207.853 * n + 29.7541) / (-n * n * n + 42.945 * n * n + 215.165 * n + 82.1357);
}
template<typename T>
int main()
{
double n;
for(auto k : {-100, -10, -1, 0, 1, 10, 100})
{
n = M_PI * pow(10.0, k);
//cout goes here
cout<<n<<" "<<cbrt(n)<<" "<<my_cbrt_2(n)<<endl;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.