How to call Mathematica in Matlab to evaluate the symbolic anonymous function?

10 vues (au cours des 30 derniers jours)
Chenguang Yan
Chenguang Yan le 29 Sep 2020
% I need to perform symbolic calculations
x1 = sym('x1');
x2 = sym('x2');
% The actual expression is very complicated
% The following expression is just an example
expression = x1.^2 + x2.^2;
% The following anonymous function is defined
% to evaluate the value of the expression
Fobj_sym = @(sol1,sol2) double(subs(expression,{x1,x2},{sol1,sol2}));
sol1 = sym('1');
sol2 = sym('2');
% I need to evaluate the anonymous function multiple times
% The execution of the following anonymous function took too much time
% MuPAD seems too slow to use
Fobj_sym(sol1,sol2)
% Q:How to call Mathematica in Matlab to evaluate the anonymous function?
% I have no experience with Mathematica

Réponses (1)

Ameer Hamza
Ameer Hamza le 29 Sep 2020
Try this code
syms x1 x2
expression(x1, x2) = x1.^2 + x2.^2;
expression(1, 2) % evaluate with x1=2, x2=2
  1 commentaire
Chenguang Yan
Chenguang Yan le 29 Sep 2020
Thanks for the reply, unfortunately it runs twice as slow as the method in the question.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by