source: CIVL/examples/arithmetic/derivative.cvl@ cc9073d

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