matrices

<< Click to Display Table of Contents >>

Navigation:  Sample Problems > Usage > Arrays+Matrices >

matrices

Previous pageReturn to chapter overviewNext page

{ MATRICES.PDE

 

 This example demonstrates a few uses of data MATRICES

}

title 'MATRIX test'

definitions

  { -- literal matrix definition -- }

   m1 = matrix((1,2,3),(4,5,6),(7,8,9))

  { -- functional matrix definition -- }

  { a 79x79 diagonal matrix of amplitude 10: }

   m2 = matrix for x(0.1 by 0.1 to 5*pi/2)    

              for y(0.1 by 0.1 to 5*pi/2)      

               :   if(x=y) then 10 else 0

  { a 79x79 matrix of sin products: }

   m3 = matrix for x(0.1 by 0.1 to 5*pi/2)      

              for y(0.1 by 0.1 to 5*pi/2)    

               :    sin(x)*sin(y) +1

  { -- literal array definition -- }

  { a 101-element array of constants: }

   v = array [79] (0.1 by 0.1 to 5*pi/2)    

  ! multiply V by matrix M3

   p = m3**v

  ! multiply V by matrix M3, scale by 1e5 and take the sine of each entry

   q = sin((m3**v)/100000)

   rad = 0.1

   s = 0

  ! solve m3*B = P

   b = p // m3

{ no variables }

{ no equations }

boundaries

  region 1

      start(0,0)

        line to (2,0) to (2,2) to (0,2) to close

{ no monitors }

plots

  elevation(q) vs v as "array vs array"

  elevation(q) as "array vs index"

  contour(m3) vs v vs v as "matrix vs two arrays"

  contour(m3) vs v as "matrix vs array and index"

  contour(m2) as "matrix vs indexes"

  surface(m3*m2) as "element product"

  surface(m3+m2) as "element sum"

  surface(m3-m2) as "element difference"

  surface(m3**m2) as "matrix product"

  elevation(b,v) as "matrix inverse times array"

  elevation(m3**b,p) as "matrix times array and array"

  summary ("selected values")

  report m3[1,1]

  report m3[3,4]

  report v[1]

  report q[1]

end