source: CIVL/examples/accuracy/secondDerivative.cvl@ 13ac9574

1.23 2.0 main test-branch
Last change on this file since 13ac9574 was 965b371, checked in by Tim Zirkel <zirkeltk@…>, 12 years ago

Updated the accuracy assumption builder. Added new examples.

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

  • Property mode set to 100644
File size: 896 bytes
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];
14double working[num_elements];
15$abstract $contin(4) double rho(double x);
16$assume h > 0;
17
18void 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
31void main() {
32 secondDerivative(h, num_elements, initial, working);
33}
Note: See TracBrowser for help on using the repository browser.