1.23
2.0
main
test-branch
| Rev | Line | |
|---|
| [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];
|
|---|
| 7 | double working[num_elements];
|
|---|
| 8 |
|
|---|
| 9 | void 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 |
|
|---|
| 20 | void 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.