Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write c++ program! I've already finished (i). Please solve (ii). Thanks in advance! Following is my answer for (i): #include #include using namespace std;

Please write c++ program! I've already finished (i). Please solve (ii). Thanks in advance!

Following is my answer for (i):

#include

#include

using namespace std;

double fun(double x)

{

return pow(x*x*x*x,1.0/3.0);

}

int main()

{

double x=0,h1,h2,h3,e1=1000,e2=1000,e3=1000;

for(int p=3;p

{

double h=pow(10,-p);

double M=(fun(x+h)-fun(x))/h;

if(fabs(M)

{

h1=h;

e1=M;

}

cout

M=(fun(x+h)-fun(x-h))/(2.0*h);

if(fabs(M)

{

h2=h;

e2=M;

}

cout

M=(-fun(x+2.0*h)+4.0*fun(x+h)-3.0*fun(x))/(2.0*h);

cout

{

h3=h;

e3=M;

}

}

cout

return 0;

}

image text in transcribed

image text in transcribed

Numerical Analysis

I have tried to do queston (ii), please improve my program. Thanks!

#include #include  // for pow() using namespace std; const double x = 1.0; // global and constant double f(double z){ double temp = (4.0/3.0); return pow(z,temp); } double df(){ double deri = (4.0/3.0) * pow(x,(1.0/3.0)); return deri; } double M1(double h){ return (double)(f(x+h) - f(x))/h; //define M1(h) } double M2(double h){ return (double)(f(x+h) - f(x-h))/(2*h); //define M2(h) } double M3(double h){ return (double)(-f(x+2*h) + 4*f(x+h) - 3*f(x))/(2*h); //define M3(h) } int main(){ double h=0.0; double m1=100.0, m2=100.0, m3=100.0; // initialize to big values to get h_crit double M1h_crit=0.0, M2h_crit=0.0, M3h_crit=0.0; // default h_crit bool m1hcrit=false, m2hcrit=false, m3hcrit=false; // in order to compute h_crit once double M1ac=1.0, M2ac=1.0, M3ac=1.0,M1Max=1.0,M2Max=1.0,M3Max=1.0,h1=3.0,h2=1.0,h3=1.0; cout  

3. a. (i) Compare the accuracy of the following three formulas for approxi- mating the derivative, f'(x): Mi(n) = f(x + h) f(x) h ) Mach)-f(x+h)-f( x 2h Mach) -f(x + 2h) + 4f (x + h) - 3f (x) 2h In particular, test the above approximations when f(x) = x/3, x = 0 or r = 1, and h = 10-P, p = 3, 4, 5,..., 20. (ii) As his decreased, the error becomes smaller, until a critical value of h is reached, after which point the error starts to increase as h decreases. Find the critical h, herit, experimentally. Note: in order to avoid problems in evaluating 24/3 when r

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Managing Your Information How To Design And Create A Textual Database On Your Microcomputer

Authors: Tenopir, Carol, Lundeen, Gerald

1st Edition

1555700233, 9781555700232

More Books

Students also viewed these Databases questions