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 
array.


Best,

Jacob

________________________________
From: lon-capa-users-boun...@mail.lon-capa.org 
<lon-capa-users-boun...@mail.lon-capa.org> on behalf of Liu, Yuk Tung 
<yt...@illinois.edu>
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 
R.

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 
[l...@egr.msu.edu]
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: 
http://search.cpan.org/~ulpfr/Math-Matrix-0.8/Matrix.pm<https://urldefense.proofpoint.com/v2/url?u=http-3A__search.cpan.org_-7Eulpfr_Math-2DMatrix-2D0.8_Matrix.pm&d=DwMFAg&c=OCIEmEwdEq_aNlsP4fF3gFqSN-E3mlr2t9JcDdfOZag&r=xsNJH7BRV_oHPnc9R-Alu7kBOiq31bgHu5mdx82zpYk&m=cZ0DC2thsyaawbW-icbHvABJUkZREthPLmF_-JF0ZzM&s=p5GS2YNIPFAqLdONRuXDul2HB4YVSlcLDsqyZRz3vDY&e=>



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: 
http://www.egr.msu.edu/~lira<https://urldefense.proofpoint.com/v2/url?u=http-3A__www.egr.msu.edu_-7Elira&d=DwMFAg&c=OCIEmEwdEq_aNlsP4fF3gFqSN-E3mlr2t9JcDdfOZag&r=xsNJH7BRV_oHPnc9R-Alu7kBOiq31bgHu5mdx82zpYk&m=cZ0DC2thsyaawbW-icbHvABJUkZREthPLmF_-JF0ZzM&s=KgidnsKWCwkMXbk-KRSFP-SdawqedYPbXqeoqnxNC70&e=>
MailScanner has detected definite fraud in the website at 
"urldefense.proofpoint.com". Do not trust this website: 
http://chethermo.net<https://urldefense.proofpoint.com/v2/url?u=http-3A__chethermo.net_&d=DwMFAg&c=OCIEmEwdEq_aNlsP4fF3gFqSN-E3mlr2t9JcDdfOZag&r=xsNJH7BRV_oHPnc9R-Alu7kBOiq31bgHu5mdx82zpYk&m=cZ0DC2thsyaawbW-icbHvABJUkZREthPLmF_-JF0ZzM&s=x_KHS9fqXQB-CLliVp9AUzDgDobPkHAATbQeAdqpNOQ&e=>





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



Hi,



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

574-520-4190
_______________________________________________
LON-CAPA-users mailing list
LON-CAPA-users@mail.lon-capa.org
http://mail.lon-capa.org/mailman/listinfo/lon-capa-users

Reply via email to