Code covered by the BSD License  

Highlights from

image thumbnail




Utilize MAXIMA CAS in MATLAB as a symbolic toolbox.

function result = maxima(str2eval) 
%MAXIMA enables the use of the MAXIMA CAS in MATLAB
% This function uses the Jacomax (Java Connector for Maxima) to start and
% connect to a session of MAXIMA.  The user passes the MAXIMA command in as
% a string and the result is returned as a string that can be used in
% conjunction with the vectorize and inline command to construct a function
% that can be evaluated and plotted in MATLAB.
%   Required Additional Software:
%   1. Maxima, which is found at:
%   2. Jacomax (Java Connector for Maxima) a basic Java interface for the 
%       Maxima computer algebra system can be found at:
%   The contents of their package must be in java class path
%     javaaddpath('jacomax-0.2.3.jar')
%     javaaddpath('slf4j-api-1.5.11.jar')
%     javaaddpath('jacomax-samples-0.2.3.jar')
%   Additionally, you must modify their file to
%   point to your installation of MAXIMA and change the file name to be
% Examples:
%    result = maxima('expand((x+2)*(x+3))')
%    result = maxima('factor(x^2+5*x+6)')
%    result = maxima('integrate(x^2+5*x+6,x)')
%    result = maxima('diff(x^2+5*x+6,x)')
% copyright Jonathan Lister per the included license.txt

persistent launcher
persistent confobj
persistent process


if isempty(process)
%create a configuration object
confobj = JacomaxPropertiesConfigurator;

%create a process launcher
launcher = MaximaProcessLauncher(confobj.configure());

%lauch MAXIMA
process = launcher.launchInteractiveProcess();

%turn off multi-line pretty print, for inline print


% wrapping the command with print puts the answer we want on the second
% line of the output
result = char(process.executeCall(['print(' str2eval ');']));

% find where the output line label starts, i.e. (%o12)
idx = regexpi(result,'\(\%o[0-9]*\)');

% using print seems to put an extra line break upfront. skip it and get the
% remaining text until we get to the output line label.
result = result(2:idx-1);

Contact us