(38G) Applying a Function to a Matrix
05-15-2015, 07:11 AM (This post was last modified: 06-12-2018 06:54 AM by Gerald H.)
Post: #1
 Gerald H Senior Member Posts: 1,452 Joined: May 2014
(38G) Applying a Function to a Matrix
The programme MFUN applies a function to matrix M1, returning the answer in M3.

The desired function should be stored in the programme FNC & take Ans as its argument.

eg To find the natural log of M1 enter the programme FNC thus:

FNC

Code:
LN(Ans):

If

M1 =
[[.1,.2,.7]
[.2,.5,.3]
[.4,.6,.3]]

MFUN returns

M3=
[[(-1.08299683723,1.64723871982),(1.31662026735,1.38974446983),(-1.53535482848E-2,-2.47915087845)]
[(.421744560769,-3.15309862062E-2),(-1.25370018315,-2.66021027682E-2),(.692275221593,4.74552177599E-2)]
[(.246905317147,-1.0105789431),(.787966638794,-.852606535171),(-.720910656896,1.52095603654)]]

As a check if FNC is then changed to

FNC

e^(Ans)

& M3 is stored in M1

MFUN returns

[[(9.99999999991E-2,-5.63571200564E-13),(.2,-1.3919361913E-12),(.700000000001,4.22835444129E-13)]
[(.2,1.16499952167E-13),(.500000000001,-2.33804747728E-13),(.300000000002,6.51270513835E-14)]
[(.399999999999,2.35369027549E-13),(.600000000001,-4.06005700045E-13),(.300000000002,3.12707095374E-13)]]

On inspection all the imaginary parts are near zero & real parts are near the original M1 values.

Here the programme:

MFUN

Code:
EIGENVV(M1)►L1: L1(1)*(1,0)►M4: Ans*0►M3: SIZE(Ans): Ans(1)►S: L1(2)*(1,0)►M2: FOR P=1 TO S STEP 1; M2(P): RUN FNC: Ans►M3(P,P): END: M4*M3*M4^-1►M3:
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)