source: CIVL/examples/experimental/positiveDefinitive.cvl@ 5bc08d6

1.23 2.0 main test-branch
Last change on this file since 5bc08d6 was 37db9bb, checked in by Manchun Zheng <zmanchun@…>, 11 years ago

added example for positive definitiveness test for matrix.

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

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/**
2 * In linear algebra, a symmetric n × n real matrix M is said to be positive definite
3 * if z^{T}Mz is positive for every non-zero column vector z of n real numbers.
4 * Here z^{T} denotes the transpose of z.
5 * SARL can't prove the query: 0<X0[1]^2+X0[0]^2
6 * under the contex: exists i : int . ((0 < -1*i+2) && (0 <= i) && (0 != X0[i]))
7 *
8*/
9
10#include<civlc.cvh>
11
12$input int n=2;
13$input double z[n];
14double M[n][n];
15$assume(n>0);
16// z is a non-zero column vector
17$assume($exists {int i | 0 <=i && i<n} z[i] != 0);
18
19// use Identity matrix for a test here
20void initialize(){
21 for(int i=0; i<n; i++){
22 for(int j=0; j<n; j++){
23 if(i==j)
24 M[i][j]=1;
25 else
26 M[i][j]=0;
27 }
28 }
29}
30
31double compute(){
32 double zTxM[n], result=0;
33 _Bool assumption=$false;
34
35 for(int i=0; i<n; i++){
36 zTxM[i]=0;
37 for(int j=0; j<n; j++){
38 // checks that M is symmetric
39 $assert(M[i][j]==M[j][i]);
40 zTxM[i]+=z[i]*M[i][j];
41 }
42 }
43 for(int i=0; i<n; i++){
44 result+=zTxM[i]*z[i];
45 }
46 $assert(result>0);
47 return result;
48}
49
50int main(){
51 initialize();
52 compute();
53}
Note: See TracBrowser for help on using the repository browser.