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

5 views (last 30 days)
% 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

Answers (1)

Ameer Hamza
Ameer Hamza on 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

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!