source: CIVL/examples/arithmetic/derivative.cvl@ 97cfc53

1.23 2.0 main test-branch
Last change on this file since 97cfc53 was 95a2a9e, checked in by Tim Zirkel <zirkeltk@…>, 13 years ago

Added new examples.

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

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