main
|
Last change
on this file 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:
1.2 KB
|
| Line | |
|---|
| 1 | #include <stdio.h>
|
|---|
| 2 | #include <math.h>
|
|---|
| 3 | #ifdef _CIVL
|
|---|
| 4 | $input double JB_INPUT;
|
|---|
| 5 | $input double alphad[10];
|
|---|
| 6 |
|
|---|
| 7 | #endif
|
|---|
| 8 | void func(double* alpha, int n, double* J) {
|
|---|
| 9 | for(int i=0;i<n;i++) {
|
|---|
| 10 | *J += sin(alpha[i]);
|
|---|
| 11 | }
|
|---|
| 12 | }
|
|---|
| 13 | void func_d(double *alpha, double *alphad, int n, double *J, double *Jd) {
|
|---|
| 14 | for (int i = 0; i < n; ++i) {
|
|---|
| 15 | *Jd = *Jd + alphad[i]*cos(alpha[i]);
|
|---|
| 16 | *J += sin(alpha[i]);
|
|---|
| 17 | }
|
|---|
| 18 | }
|
|---|
| 19 | void func_b(double *alpha, double *alphab, int n, double *J, double *Jb) {
|
|---|
| 20 | for (int i = n-1; i > -1; --i) {
|
|---|
| 21 | alphab[i] = alphab[i] + cos(alpha[i])*(*Jb);
|
|---|
| 22 | }
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 | int main(int argc, char** argv) {
|
|---|
| 27 | // dot product test: alphad*alphab == Jd*Jb
|
|---|
| 28 | const int n = 10;
|
|---|
| 29 | double alpha[n], alphad[n], alphab[n];
|
|---|
| 30 | double J, Jd, Jb;
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 | for(int i=0; i<n; i++) {
|
|---|
| 34 | alpha[i] = 1.5*i;
|
|---|
| 35 | alphab[i] = 0.0;
|
|---|
| 36 | }
|
|---|
| 37 | J = 0.0;
|
|---|
| 38 | Jd = 0.0;
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 | #ifdef _CIVL
|
|---|
| 42 | Jb = JB_INPUT;
|
|---|
| 43 | for(int i=0; i<n; i++) {
|
|---|
| 44 | alphad[i] = 0.0;
|
|---|
| 45 | }
|
|---|
| 46 | alphad[3] += 1;
|
|---|
| 47 | #else
|
|---|
| 48 | Jb = 1.0
|
|---|
| 49 | #endif
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 | func(&alpha[0],n,&J);
|
|---|
| 53 | func_d(&alpha[0],&alphad[0],n,&J,&Jd);
|
|---|
| 54 | func_b(&alpha[0],&alphab[0],n,&J,&Jb);
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 | double dp = 0.0;
|
|---|
| 58 | for(int i=0;i<n;i++) {
|
|---|
| 59 | dp += alphad[i]*alphab[i];
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 | printf("%f %f\n",dp, Jd*Jb);
|
|---|
| 64 | } |
|---|
Note:
See
TracBrowser
for help on using the repository browser.