source: CIVL/examples/accuracy/secondDerivativeBad.cvl@ bf71f8f

1.23 2.0 main test-branch
Last change on this file since bf71f8f was d980649, checked in by Manchun Zheng <zmanchun@…>, 10 years ago

fixed extra parenthesis.

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

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