[LON-CAPA-users] {Disarmed} Re: {Disarmed} RE: Matrix Operations

Jacob Bond bond13 at purdue.edu
Tue Feb 13 13:51:17 EST 2018

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.



From: lon-capa-users-bounces at mail.lon-capa.org <lon-capa-users-bounces at mail.lon-capa.org> on behalf of Liu, Yuk Tung <ytliu at 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-bounces at mail.lon-capa.org [lon-capa-users-bounces at mail.lon-capa.org] on behalf of Carl Lira [lira at 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-bounces at mail.lon-capa.org [mailto:lon-capa-users-bounces at 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 at 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.lon-capa.org/pipermail/lon-capa-users/attachments/20180213/18b70f18/attachment.html>

More information about the LON-CAPA-users mailing list