Trying to use Symbolic engine - Mupad or Maple

Hello,
I had used the Maple symbolic engine in matlab version 2007b and 2010b. However in R2012a, code such as:
M = maple('GenerateMatrix', eqset, gunkset, 'augmented=true', 'outputoptions=[storage=sparse]');
which uses strictly Maple functions no longer works, since there appears to be no way to change the symbolic engine from Mupad to Maple.
First, is it possible to change the symbolic engine to Maple in R2012a ?
Second, I tried using Mupad to do the same calculations: I tried the following as a test, on the command line:
syms x y
eqs = [2*x + y - 1, x + y - 2];
unks = [x, y];
s = feval(symengine, 'linsolve', eqs, unks);
I get the following error:
??? Error using ==> mupadengine.mupadengine>mupadengine.feval at 141 Error: expecting set or list of equations [linsolve]
I'm simply not able to figure out what is going wrong. (The mupadengine.m file appears to convert the arguments into some internal form represented by the identifier _symans_32_8 and so on).
Note that if I write:
s = feval(symengine, 'linsolve', '[2*x + y - 1, x + y - 2]', '[x, y]');
then there is no error and the equation is solved successfully. However, in my particular application, the equations are generated on the fly. Moreover, obtaining a matrix A (to solve Ax = b) is very inconvenient. The Maple function 'GenerateMatrix' (see above), did the needful when the Maple engine was available but I don't see any equivalent in Mupad.
I also tried:
s = feval(symengine, 'linsolve', char(eqs), char(unks));
but the error remains.
Would be grateful if anyone has any comments.
Best Regards,
Sandeep.

6 comentarios

Hi, could you tell me where did you get this syntax:
M = maple('GenerateMatrix', eqset, gunkset, 'augmented=true', 'outputoptions=[storage=sparse]');
I have troubles in Matlab programming using Maple symbolic engine.
Best wishes.
The general syntax for calling into the Extended Mathematics Toolbox (no longer available from Mathworks) or the Maple engine (using Maple Toolbox for MATLAB, from Maplesoft) is
result = maple('Expression')
or
result = maple('FunctionName', parameter, parameter, parameter...)
GenerateMatrix(eqns, vars, aug, options)
Parameters
eqns - list or set of (linear) equations or expressions
vars - list or set of variables in which the equations occur
aug - (optional) equation of the form augmented=true or false; specifies how result is returned
options - (optional); constructor options for the result object
When looking at that documentation, pay attention to the fact that the context is listed as LinearAlgebra and that the example starts with
with(LinearAlgebra):
In Maple, that is a request to import function names from the Maple LinearAlgebra package, making it possible to refer to refer to GenerateMatrix as a function name on its own, instead of using the complete name LinearAlgebra[GenerateMatrix] or LinearAlgebra:-GenerateMatrix -- if you have not done a
maple('with(LinearAlgebra):')
then maple will not be able to find GenerateMatrix by that name.
zhang sifei
zhang sifei el 9 de Nov. de 2019
Editada: zhang sifei el 9 de Nov. de 2019
Thank you very much, Sir, you are awesome and kindful.
By the way, I still encounter some troubles in using 'GenerateMatrix'. Hope you can help me again. The following codes run wrong. And the response of Matlab are below.
% Set symbolic variables.
x=sym('x');
y=sym('y');
z=sym('z');
eqns=sym('eqns',[1 3]); % 3*1 array.(Already testify it is correct)
u=[x+2*y+3;y-4*z;2*z+5*y-x/2];
v=[2*x+y;4*y-z;5*z+2*y-x];
% Obtain equations.
for i=1:3
eqns(i,1)=maple('simplify',u(i,1)-v(i,1));
% Maybe the wrong is caused by eqns(1,1)=-x+y+3, which should be eqns(1,1)=-x+y+3==0.
% But I have tried it, the wrong always occurs.
end
% Using 'GenerateMatrix' to transform eqns to matrix.
maple('with(LinearAlgebra):');
var=[x;y;z];
B=maple('GenerateMatrix',eqns, var);
the response of Matlab:
Error using sym/maple (line 43)
Error using maplemex
Error, invalid input: LinearAlgebra:-GenerateMatrix expects its 1st argument, eqns, to be of type {list, set}({=, algebraic}), but received Vector(3,
[-x+y+3,-3*y-3*z,-3*z+3*y+1/2*x])
Error in eqnsToMatrix_maple (line 58)
B=maple('GenerateMatrix',eqns, var);
I don't know why, and what is the valid input? {list, set}({=, algebraic}) ???
Experiment:
Replace
B=maple('GenerateMatrix',eqns, var);
with
eqns_list = maple('convert', eqns, 'list');
vars_list = maple('convert', 'var', 'list');
B=maple('GenerateMatrix',eqns_list, vars_list);
zhang sifei
zhang sifei el 9 de Nov. de 2019
Editada: zhang sifei el 9 de Nov. de 2019
Dear Walter Roberson,
Thank you very much. May peace and love fill your heart, and contentment and joy fill your days.
Best regards,
Zhang Sifei.
Dear Walter Roberson,
could you help me how to solve this problem?
The wrong code is
T(i,1)=T(i,1)+w*(u(j,1)-u(i,1))*v*f;
and the sym/subsasgn (line 64) is
The original question is

Iniciar sesión para comentar.

Respuestas (2)

Walter Roberson
Walter Roberson el 20 de Jul. de 2012

0 votos

I do not recall the exact release at the moment, but symengine can no longer be changed.
SK
SK el 24 de Jul. de 2012

0 votos

Does anyone know why the Mupad connection does not work ? Incidentally, 'solve' works with similar code, but not 'linsolve'.
Regards, Sandeep

Preguntada:

SK
el 20 de Jul. de 2012

Comentada:

el 26 de Nov. de 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by