EMPS intranet

Hi!   Hi!           Start main()

### Try stepping through the code

Value and type of last evaluated expression: Address of array element: Address of array elementx:  (none)

Your browser does not support the canvas element which will make some the features unavailable.

If you are using Internet Explorer within the University of Exeter try going to the Settings menu (probably the gear shape at the top right of this page), selecting "Compatibility View settings", unchecking "Display intranet sites in Compatibility View" and reloading this page.

### Code

``` Header...
/*
* Demonstrate the use of successive halving to solve
* atan(x) + exp(x) + fabs(log(x) = y
*/

int main(){   ...
»  double y, ytarget=11.789474563, x, xmin=0, xmax=ytarget;

»  printf("Diag: target is %g\n", ytarget);
»  do{
»    x=(xmin+xmax)/2.0;
»    y=atan(x)+exp(x)+fabs(log(x));

»    printf("Diag: xmin = %g, xmax = %g, y = %g\n", xmin, xmax, y);

»    if (y<ytarget)
xmin=x;
else
xmax=x;
}while (fabs(y-ytarget)>1e-6) ;

»  printf("The solution is %g\n", x);
»  return 0;
}
```
Memory

### main()

128
129
130
131
132
133
134
135
y = -7.09085148e+266
136
137
138
139
140
141
142
143
ytarget = 11.7894746
144
145
146
147
148
149
150
151
x = -2.11201922e+267
152
153
154
155
156
157
158
159
xmin = 0
160
161
162
163
164
165
166
167
xmax = 11.7894746

NB: the actual memory address of each variable is the

.
Show output (Before looking at the output, work out what you think it put should be and see if you are right.)

#### Output

```Diag: target is 11.7895
Diag: xmin = 0, xmax = 11.7895, y = 366.298
Diag: xmin = 0, xmax = 5.89474, y = 21.3804
Diag: xmin = 0, xmax = 2.94737, y = 5.72765
Diag: xmin = 1.47368, xmax = 2.94737, y = 11.0597
Diag: xmin = 2.21053, xmax = 2.94737, y = 15.3315
Diag: xmin = 2.21053, xmax = 2.57895, y = 13.0138
Diag: xmin = 2.21053, xmax = 2.39474, y = 11.9956
Diag: xmin = 2.21053, xmax = 2.30263, y = 11.5179
Diag: xmin = 2.25658, xmax = 2.30263, y = 11.7542
Diag: xmin = 2.27961, xmax = 2.30263, y = 11.8743
Diag: xmin = 2.27961, xmax = 2.29112, y = 11.8141
Diag: xmin = 2.27961, xmax = 2.28536, y = 11.7841
Diag: xmin = 2.28248, xmax = 2.28536, y = 11.7991
Diag: xmin = 2.28248, xmax = 2.28392, y = 11.7916
Diag: xmin = 2.28248, xmax = 2.2832, y = 11.7879
Diag: xmin = 2.28284, xmax = 2.2832, y = 11.7897
Diag: xmin = 2.28284, xmax = 2.28302, y = 11.7888
Diag: xmin = 2.28293, xmax = 2.28302, y = 11.7893
Diag: xmin = 2.28298, xmax = 2.28302, y = 11.7895
Diag: xmin = 2.28298, xmax = 2.283, y = 11.7894
Diag: xmin = 2.28299, xmax = 2.283, y = 11.7894
Diag: xmin = 2.283, xmax = 2.283, y = 11.7895
The solution is 2.283
```