Hi all,

Given an array @mat of matrix entries, this will build the Maxima syntax for 
the $rows x $cols matrix with entries @mat:

my $maxima_mat = 'matrix(';
my @mat_copy = @mat;
for my $i (0..$rows-1) {
    my @row = splice(@mat_copy, 0, $cols);
    $maxima_mat .= '['.join(',', @row).']';
    if ($i != $rows-1) {$maxima_mat .= ',';}
$maxima_mat .= ')';

Then you can invert it and break it back into an array like this:

my $inv = cas('maxima', "list_matrix_entries(invert($maxima_mat));");
$inv =~ s/\[|\]//g; #remove the leading and trailing []
my @mat_inv = split(',', $inv);

I suppose it's not the prettiest, but it's certainly shorter than Perl 
functions for all of the matrix operations.  You could even wrap the code into 
Perl functions matrix_to_maxima and matrix_from_maxima.  You could also write 
similar functions if you are using a Perl "matrix" 
(https://perlmaven.com/multi-dimensional-arrays-in-perl) instead of a flat 



From: lon-capa-users-boun...@mail.lon-capa.org 
<lon-capa-users-boun...@mail.lon-capa.org> on behalf of Liu, Yuk Tung 
Sent: Tuesday, February 13, 2018 12:08:23 PM
To: Discussion list for LON-CAPA users
Subject: [LON-CAPA-users] {Disarmed} RE: Matrix Operations

Hi all,

Lon Capa supports both Maxima and R. They can be used to do matrix operations. 
I can't find examples involving matrix, but you can go to  
https://loncapa.msu.edu/adm/help/Creating_Math_Response_Problems.hlp and 
http://www.lon-capa.org/documentation.html to see examples of using Maxima and 

A couple years ago, I wanted to create problems involving regressions. I used R 
to do that, but it only worked if the data size was not too big. So I wrote my 
own perl functions to perform regressions. Regressions involve matrix 
inversion, which I used Cholesky decomposition since the matrix I worked with 
is symmetric and positive-definite.

Yuk Tung Liu
E-Learning Specialist
Department of Statistics
University of Illinois

From: lon-capa-users-boun...@mail.lon-capa.org 
[lon-capa-users-boun...@mail.lon-capa.org] on behalf of Carl Lira 
Sent: Tuesday, February 13, 2018 8:55 AM
To: 'Discussion list for LON-CAPA users'
Subject: Re: [LON-CAPA-users] Matrix Operations

Hi Gene,

I would take advantage of this also. I see some matrix operations available, 
but I don’t know if the module is installed.

MailScanner has detected definite fraud in the website at 
"urldefense.proofpoint.com". Do not trust this website: 

Carl Lira

Associate Professor
Department of Chemical Engineering and Materials Science
2100 Engineering Building
428 S. Shaw Lane
Michigan State University
East Lansing, MI 48824-1226
Phone: (517) 355-9731
FAX: (517)432-1105
MailScanner has detected definite fraud in the website at 
"urldefense.proofpoint.com". Do not trust this website: 
MailScanner has detected definite fraud in the website at 
"urldefense.proofpoint.com". Do not trust this website: 

From: lon-capa-users-boun...@mail.lon-capa.org 
[mailto:lon-capa-users-boun...@mail.lon-capa.org] On Behalf Of Harding, Gene L
Sent: Saturday, February 10, 2018 9:56 PM
To: Discussion list for LON-CAPA users <lon-capa-users@mail.lon-capa.org>
Subject: [LON-CAPA-users] Matrix Operations


Does LON-CAPA have any provision for doing matrix operations (e.g., 
multiplication, inverse calculation or equivalent of the MATLAB “\” operator)?

Best regards,

Gene L. Harding, PE

Associate Professor of ECET

LON-CAPA-users mailing list

Reply via email to