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

main test-branch
Last change on this file since bb03188 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

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

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