The purpose of this function is to return the index i of the segment [Li, Zi+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. /* Given an array of coordinates xi for an 2 * ordered uniform grid of size n and a 3 4 ▾ 5 * 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 6 * i.e. xi[i+1] - xi[i] > 0) */ 7▾ int locate(int n, double *xi, double x) { 8 9 10 11 0123 12 13 14 15 16 17 18 19 20 21 23▾ 72222222222≈2mmmm 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 < a && x > b) { 24 25 26 } 28 29 30 31 32} 33 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 [Li, Zi+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. /* Given an array of coordinates xi for an 2 * ordered uniform grid of size n and a 3 4 ▾ 5 * 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 6 * i.e. xi[i+1] - xi[i] > 0) */ 7▾ int locate(int n, double *xi, double x) { 8 9 10 11 0123 12 13 14 15 16 17 18 19 20 21 23▾ 72222222222≈2mmmm 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 < a && x > b) { 24 25 26 } 28 29 30 31 32} 33 printf("ERROR: Point lies outside the grid.\n"); return -1; /* Find index assuming uniform grid */ idx = round((x-a)/dx); return idx;
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
There are 4 mistakes in the code. Can you please show me the mistakes?
![The purpose of this function is to return the index i of the segment
[Li, Zi+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. /* Given an array of coordinates xi for an
2 * ordered uniform grid of size n and a
3
4 ▾
5
* 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
6 * i.e. xi[i+1]
-
xi[i] > 0) */
7▾ int locate(int n, double *xi, double x) {
8
9
10
11
0123
12
13
14
15
16
17
18
19
20
21
23▾
72222222222≈2mmmm
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 < a && x > b) {
24
25
26
}
28
29
30
31
32}
33
printf("ERROR: Point lies outside the grid.\n");
return -1;
/* Find index assuming uniform grid */
idx =
round((x-a)/dx);
return idx;](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F45cf69fb-b0ff-4b62-bc2e-e4054fc1f593%2Fd3599206-7114-484f-a949-4dfb3a758b24%2Fvh9voag_processed.png&w=3840&q=75)
Transcribed Image Text:The purpose of this function is to return the index i of the segment
[Li, Zi+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. /* Given an array of coordinates xi for an
2 * ordered uniform grid of size n and a
3
4 ▾
5
* 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
6 * i.e. xi[i+1]
-
xi[i] > 0) */
7▾ int locate(int n, double *xi, double x) {
8
9
10
11
0123
12
13
14
15
16
17
18
19
20
21
23▾
72222222222≈2mmmm
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 < a && x > b) {
24
25
26
}
28
29
30
31
32}
33
printf("ERROR: Point lies outside the grid.\n");
return -1;
/* Find index assuming uniform grid */
idx =
round((x-a)/dx);
return idx;
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

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education