source: CIVL/examples/accuracy/secondDerivative.cvl@ b2a2faa

1.23 2.0 main test-branch
Last change on this file since b2a2faa was 3ff27cf, checked in by Manchun Zheng <zmanchun@…>, 11 years ago

updated examples since $assert/$assume has been changed to functions; fixed the model builder for the new side-effect remover.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@2085 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 810 bytes
Line 
1/* Commandline execution:
2 * civl verify -inputnum_elements=5 secondDerivative.cvl
3 *
4 * Note: based on Quarteroni, Sacco, Saleri. "Numerical Mathematics" 2nd ed. sec 10.10.1
5 *
6 * */
7#include<civlc.cvh>
8
9$input double h;
10$input int num_elements = 5;
11$input double initial[num_elements];
12double working[num_elements];
13$abstract $contin(4) $real rho($real x);
14$assume(h > 0);
15
16void secondDerivative(double h, int n, double y[], double result[]){
17 int i;
18
19 $assume($forall {m=0 .. n-1} y[m] == rho(m*h));
20 for(i = 1; i < n-1; i++)
21 {
22 result[i] = (y[i+1]-2*y[i]+y[i-1])/(h*h);
23 }
24 result[0] = (y[2]-2*y[1]+y[0])/h;
25 result[n-1] = (y[n-3] - 2*y[n-2]-y[n-1])/h;
26 $assert(($uniform {k=1 .. n-2} result[k]-$D[rho,{x,2}](k*h) == $O(h*h)));
27}
28
29void main() {
30 secondDerivative(h, num_elements, initial, working);
31}
Note: See TracBrowser for help on using the repository browser.