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;
Algebra & Trigonometry with Analytic Geometry
13th Edition
ISBN:9781133382119
Author:Swokowski
Publisher:Swokowski
Chapter1: Fundamental Concepts Of Algebra
Section1.2: Exponents And Radicals
Problem 92E
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
Algebra & Trigonometry with Analytic Geometry
Algebra
ISBN:
9781133382119
Author:
Swokowski
Publisher:
Cengage
Algebra & Trigonometry with Analytic Geometry
Algebra
ISBN:
9781133382119
Author:
Swokowski
Publisher:
Cengage