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

10 ビュー (過去 30 日間)
Chenguang Yan
Chenguang Yan 2020 年 9 月 29 日
編集済み: Walter Roberson 2020 年 9 月 29 日
% 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
  1 件のコメント
Chenguang Yan
Chenguang Yan 2020 年 9 月 29 日
編集済み: Walter Roberson 2020 年 9 月 29 日
I installed the following toolbox, but I don’t know how to solve this problem.

サインインしてコメントする。

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 9 月 29 日
Try this code
syms x1 x2
expression(x1, x2) = x1.^2 + x2.^2;
expression(1, 2) % evaluate with x1=2, x2=2
  1 件のコメント
Chenguang Yan
Chenguang Yan 2020 年 9 月 29 日
Thanks for the reply, unfortunately it runs twice as slow as the method in the question.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by