The purpose of this function is to return the index i of the segment [xi, Xi+1] that contains x. Its input arguments are: int n: the size of the grid (number of grid points) double *xi: the array of size n containing the grid coordinates double x: the coordinate of the point that we want to locate There are 4 mistakes (bugs) in this function. Find them and fix them! Answer: (penalty regime: 10, 20, ... %) Reset answer 1 2 3 4- 5 6 7 8 9 10 11 68694AWNE 14 15 16 17 18 19 20 E221222222222222223333 Given an array of coordinates xi for an * ordered uniform grid of size n and a * value x, locate the index i for which x \in [xi[i], xi [i+1]). (We assume that *the grid is given in incremental order * * i.e. xi[i+1] - xi[i] > 0) * int locate(int n, double *xi, double x) { int idx; double a, b, dx; /* assign edge values of interpolation interval */ a = xi [0] b = xi[n-1]; /* Calculate step size */ dx = (b-a)/(n); /* Special treatment if x-b */ if (x b) return n-1; /* Check that x \in [a,b] */ if (x b) { 23 24 25 26 } 27 28 29 30 32} printf("ERROR: Point lies outside the grid.\n"); return -1; Find index assuming uniform grid */ idx round((x-a)/dx); return idx;
The purpose of this function is to return the index i of the segment [xi, Xi+1] that contains x. Its input arguments are: int n: the size of the grid (number of grid points) double *xi: the array of size n containing the grid coordinates double x: the coordinate of the point that we want to locate There are 4 mistakes (bugs) in this function. Find them and fix them! Answer: (penalty regime: 10, 20, ... %) Reset answer 1 2 3 4- 5 6 7 8 9 10 11 68694AWNE 14 15 16 17 18 19 20 E221222222222222223333 Given an array of coordinates xi for an * ordered uniform grid of size n and a * value x, locate the index i for which x \in [xi[i], xi [i+1]). (We assume that *the grid is given in incremental order * * i.e. xi[i+1] - xi[i] > 0) * int locate(int n, double *xi, double x) { int idx; double a, b, dx; /* assign edge values of interpolation interval */ a = xi [0] b = xi[n-1]; /* Calculate step size */ dx = (b-a)/(n); /* Special treatment if x-b */ if (x b) return n-1; /* Check that x \in [a,b] */ if (x b) { 23 24 25 26 } 27 28 29 30 32} printf("ERROR: Point lies outside the grid.\n"); return -1; Find index assuming uniform grid */ idx round((x-a)/dx); return idx;
Advanced Engineering Mathematics
10th Edition
ISBN:9780470458365
Author:Erwin Kreyszig
Publisher:Erwin Kreyszig
Chapter2: Second-order Linear Odes
Section: Chapter Questions
Problem 1RQ
Related questions
Question
Using C++
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 1 steps
Recommended textbooks for you
Advanced Engineering Mathematics
Advanced Math
ISBN:
9780470458365
Author:
Erwin Kreyszig
Publisher:
Wiley, John & Sons, Incorporated
Numerical Methods for Engineers
Advanced Math
ISBN:
9780073397924
Author:
Steven C. Chapra Dr., Raymond P. Canale
Publisher:
McGraw-Hill Education
Introductory Mathematics for Engineering Applicat…
Advanced Math
ISBN:
9781118141809
Author:
Nathan Klingbeil
Publisher:
WILEY
Advanced Engineering Mathematics
Advanced Math
ISBN:
9780470458365
Author:
Erwin Kreyszig
Publisher:
Wiley, John & Sons, Incorporated
Numerical Methods for Engineers
Advanced Math
ISBN:
9780073397924
Author:
Steven C. Chapra Dr., Raymond P. Canale
Publisher:
McGraw-Hill Education
Introductory Mathematics for Engineering Applicat…
Advanced Math
ISBN:
9781118141809
Author:
Nathan Klingbeil
Publisher:
WILEY
Mathematics For Machine Technology
Advanced Math
ISBN:
9781337798310
Author:
Peterson, John.
Publisher:
Cengage Learning,