Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Programming question about multiple assignments in the Coefficients Matrix

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28508] Re: Programming question about multiple assignments in the Coefficients Matrix
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Tue, 24 Apr 2001 01:48:46 -0400 (EDT)
  • Organization: Universitaet Leipzig
  • References: <9btras$1up@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

aa[n_, lst_] :=
  Module[{k},
    Set @@@ ( {k @@ Take[#, 2], Last[#]} & /@ lst);
    k[i_, j_] := 0;
    DiagonalMatrix[Table[-Sum[k[i, j], {j, 0, n}], {i, 1, n}]] + 
      Table[k[j, i], {i, 1, n}, {j, 1, n}]
    
    ]


and

aa[3, {{1, 2, 2}, {2, 1, 1}, {1, 0, 0.7}, {1, 3, 0.3}, {3, 0, 1}, {3, 1,
1}}]

will create the matrix.

Regards
  Jens


"J. Guillermo Sanchez" wrote:
> 
> Dear friends:
> 
> I have built the following expressions
> 
> A[n_] := Module[{A}, A = DiagonalMatrix[Table[-Sum[k[i, j], {j, 0,
> n}], {i, 1, n}]] + Table[k[j, i], {i, 1, n}, {j, 1, n}]];
> 
> k[i_,j_,a_:h]:=k[i,j]= Block[{h=0},a];
> 
> (This matrix is usually called Coefficients Matrix)
> 
> With these functions I obtain the solution that I was looking for. For
> instance:
> 
> k[1,2,2] ;k[2,1,1];k[1,0,0.7];k[1,3,0.3] ;k[3,0,1];k[3,1,1];
> 
> A[3]//MatrixForm
> 
> But need to apply the above functions in only one sentence to make a
> package. I mean, I wish build a function like this (of course it doesn't
> work)
> 
> A[n_, k[i_,j_,a_:h]]:=
> 
> Module[{k,A},A=DiagonalMatrix[Table[-Sum[k[i,j],{j,0,n}],{i,1,n}]]+Table[k[j,i],{i,1,n},{j,1,n}]; k=k[i,j]=Block[{h=0},a];A]
> 
> In the way that it was applied obtaining the same solution that before
> 
> A[3,k[1,2,2];k[2,1,1];k[1,0,0.7];k[1,3,0.3];k[3,0,1];k[3,1,1]];
> 
> Any suggestion?


  • Prev by Date: Re: ListPlot with row vectors
  • Next by Date: Re: Two questions concerning ListDensityPlot ...
  • Previous by thread: Programming question about multiple assignments in the Coefficients Matrix
  • Next by thread: ListPlot with row vectors