1.23
2.0
main
test-branch
| Line | |
|---|
| 1 | /* Commandline execution:
|
|---|
| 2 | * civl verify -inputnum_elements=5 secondDerivativeBad.cvl
|
|---|
| 3 | *
|
|---|
| 4 | * Note: based on Quarteroni, Sacco, Saleri. "Numerical Mathematics" 2nd ed. sec 10.10.1
|
|---|
| 5 | *
|
|---|
| 6 | * This version erroneously assumes that the method is 3rd order accurate in terms of h.
|
|---|
| 7 | * */
|
|---|
| 8 | #include<civlc.h>
|
|---|
| 9 | #include<stdio.h>
|
|---|
| 10 |
|
|---|
| 11 | $input double h;
|
|---|
| 12 | $input int num_elements;
|
|---|
| 13 | $input double initial[num_elements];
|
|---|
| 14 | double working[num_elements];
|
|---|
| 15 | $abstract $contin(4) double rho(double x);
|
|---|
| 16 | $assume h > 0;
|
|---|
| 17 |
|
|---|
| 18 | void secondDerivative(double h, int n, double y[], double result[]){
|
|---|
| 19 | int i;
|
|---|
| 20 |
|
|---|
| 21 | $assume $forall {m=0 .. n-1} y[m] == rho(m*h);
|
|---|
| 22 | for(i = 1; i < n-1; i++)
|
|---|
| 23 | {
|
|---|
| 24 | result[i] = (y[i+1]-2*y[i]+y[i-1])/(h*h);
|
|---|
| 25 | }
|
|---|
| 26 | result[0] = (y[1]-y[0])/h;
|
|---|
| 27 | result[n-1] = (y[n-1] - y[n-2])/h;
|
|---|
| 28 | $assert($uniform {k=1 .. n-2} result[k]-$D[rho,{x,2}](k*h) == $O(h*h));
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | void main() {
|
|---|
| 32 | secondDerivative(h, num_elements, initial, working);
|
|---|
| 33 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.