On Tue, Mar 8, 2011 at 4:38 AM, Tomasz Jankowski <span dir="ltr">&lt;<a href="mailto:tomjan@jay.au.poznan.pl">tomjan@jay.au.poznan.pl</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Matlab pseudo code<br>
A = diag([1 1 1])<br>
<br>
So table is sth like this<br>
i  j  val<br>
0 0 1<br>
1 1 1<br>
2 2 1<br>
<br>
see this<br>
<br>
Mat A; // of course, A should be created first and assembled after the set operation<br>
int m =3;<br>
int n = 3;<br>
PetscInt indxm [] ={0, 1, 2};<br>
PetscInt indxn [] = {0, 1, 2};<br>
PetscScalar vals[] = {1.,1.,1.}<br>
MatSetValues(A, m, idxm, n, idxn, vals, INSERT_VALUES);<br>
</blockquote>
<br>
<br>
you example doen&#39;t work<br>
the result matrix is:<br>
<br>
row 0: (0, 1.1)  (1, 1.2)  (2, 1.3)<br>
row 1: (0, 2.07356e-317)  (1, 2.122e-314)  (2, 9.88131e-324)<br>
row 2: (0, 2.122e-314)  (1, 9.88131e-324)  (2, 1.40122e-316)<br>
<br>
tom<br>
<br>
here is the code for this example<br>
<br>
  Mat xx;<br>
  PetscInitialize(&amp;argc,&amp;argv,(char *)0,help);<br>
<br>
  MatCreateSeqAIJ(PETSC_COMM_SELF,3,3,1,PETSC_NULL,&amp;xx);<br>
<br>
  int m =3;<br>
  int n = 3;<br></blockquote><div>    ^^^^^^^^^^</div><div><br></div><div>This is wrong. You are claiming to provide a m x n array of values, but you only give 3, not 9 values.</div><div>If you want a diagonal matrix, either change to MatSetDiagonal(), or use</div>
<div><br></div><div> m = 1;</div><div> n = 1;</div><div><br></div><div><meta charset="utf-8"> MatSetValues(xx,m,indxm,n,indxn,vals,INSERT_VALUES);<br></div><div><meta charset="utf-8"> MatSetValues(xx,m,&amp;indxm[1],n,&amp;indxn[1],&amp;vals[1],INSERT_VALUES);<br>
</div><div><meta charset="utf-8"> MatSetValues(xx,m,&amp;indxm[2],n,&amp;indxn[2],&amp;vals[2],INSERT_VALUES);<br></div><div><br></div><div>You set rows of values, or logically dense matrices of values (like element matrices) at a time.</div>
<div><br></div><div>    Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
  PetscInt indxm [] ={0, 1, 2};<br>
  PetscInt indxn [] = {0, 1, 2};<br>
  PetscScalar vals[] = {1.1,1.2,1.3};<br>
<br>
  MatSetValues(xx,m,indxm,n,indxn,vals,INSERT_VALUES);<br>
<br>
  MatAssemblyBegin(xx,MAT_FINAL_ASSEMBLY);<br>
  MatAssemblyEnd(xx,MAT_FINAL_ASSEMBLY);<br>
<br>
  MatView(xx,PETSC_VIEWER_STDOUT_WORLD);<br>
  PetscFinalize();<br>
<br>
return EXIT_SUCCESS;<br>
</blockquote></div><br><br clear="all"><br>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener<br>