main
| Line | |
|---|
| 1 | /* Commandline execution:
|
|---|
| 2 | * civl verify derivative.cvl
|
|---|
| 3 | */
|
|---|
| 4 | $input double h;
|
|---|
| 5 | $input int num_elements;
|
|---|
| 6 | $assume( num_elements > 0);
|
|---|
| 7 | $input double initial[num_elements];
|
|---|
| 8 | $output double final[num_elements];
|
|---|
| 9 | double working[num_elements];
|
|---|
| 10 |
|
|---|
| 11 | void differentiate(double h, int n, double y[], double result[]){
|
|---|
| 12 | int i;
|
|---|
| 13 |
|
|---|
| 14 | for(i = 1; i < n-1; i++)
|
|---|
| 15 | {
|
|---|
| 16 | result[i] = (y[i+1]-y[i-1])/(2*h);
|
|---|
| 17 | }
|
|---|
| 18 | result[0] = (y[1]-y[0])/h;
|
|---|
| 19 | result[n-1] = (y[n-1] - y[n-2])/h;
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | void main() {
|
|---|
| 23 | int i;
|
|---|
| 24 |
|
|---|
| 25 | $assume(h > 0);
|
|---|
| 26 | $assume(num_elements > 2 && num_elements <= 5);
|
|---|
| 27 | differentiate(h, num_elements, initial, working);
|
|---|
| 28 | for(i=0; i < num_elements; i++) {
|
|---|
| 29 | final[i] = working[i];
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.