source: CIVL/examples/arithmetic/derivative.cvl

main
Last change on this file was b689afd, checked in by Stephen Siegel <siegel@…>, 4 weeks ago

Getting rid of unused examples that are not good and starting to clean
up others.

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

  • Property mode set to 100644
File size: 665 bytes
Line 
1/* Commandline execution:
2 * civl verify derivative.cvl
3 */
4$input double h;
5$input int num_elements;
6$assume( num_elements > 0);
7$input double initial[num_elements];
8$output double final[num_elements];
9double working[num_elements];
10
11void differentiate(double h, int n, double y[], double result[]){
12 int i;
13
14 for(i = 1; i < n-1; i++)
15 {
16 result[i] = (y[i+1]-y[i-1])/(2*h);
17 }
18 result[0] = (y[1]-y[0])/h;
19 result[n-1] = (y[n-1] - y[n-2])/h;
20}
21
22void main() {
23 int i;
24
25 $assume(h > 0);
26 $assume(num_elements > 2 && num_elements <= 5);
27 differentiate(h, num_elements, initial, working);
28 for(i=0; i < num_elements; i++) {
29 final[i] = working[i];
30 }
31}
32
33
Note: See TracBrowser for help on using the repository browser.