Firstly, Matlab communicates with MuPAD via string commands so ultimately there is no way of getting around the use of strings. And because it's the native format, if you're passing large amounts of data into MuPAD, the best approach will be to convert everything to strings fast and efficiently (sprintf
is usually best). However, in your case, I think that you can use feval
instead of evalin
which allows you to pass in regular Matlab datatypes (under the hood sym/feval
does the string conversion and calls evalin
). This method is discussed in this MathWorks article. The following code could be used:
T = [0 0 0 0 0 0 0 0 0 0 1 0 1 0 1];
syms u v;
eq1 = -T(13)*u^4 + (4*T(15) - 2*T(10) - T(11)*v)*u^3 + (3*T(13) - 3*T(6) ...
+ v*(3*T(14) -2*T(7)) - T(8)*v^2)*u^2 + (2*T(10) - 4*T(1) + v*(2*T(11) ...
- 3*T(2)) + v^2*(2*T(12) - 2*T(3)) - T(4)*v^3)*u + v*(T(7) + T(8)*v ...
+ T(9)*v^2) + T(6);
eq2 = (T(14) - T(13)*v)*u^3 + u^2*(T(11) + (2*T(12) - 2*T(10))*v ...
- T(11)*v^2) + u*(T(7) + v*(2*T(8) - 3*T(6) ) + v^2*(3*T(9) - 2*T(7)) ...
- T(8)*v^3) + v*(2*T(3) - 4*T(1) + v*(3*T(4) - 3*T(2)) + v^2*(4*T(5) ...
- 2*T(3)) - T(4)*v^3) + T(2);
allSolutions = feval(symengine, 'numeric::polysysroots',[eq1,eq2],'[u,v]');
The last argument still needed to be a string (or omitted) and adding ==0
to the equations also doesn't work, but the zero is implicit anyways.
For the second question, the result returned by numeric::polysysroots
is very inconvenient and not easy to work with. It's a set (DOM_SET
) of matrices. I tried using coerce
to convert the result to something else to no avail. I think you best bet it to convert the output to a string (using char
) and parse the result. I do this for simpler output formats. I'm not sure if it will be helpful, but feel free to look at my sym2float
which just handles symbolic matrices (the 'matrix([[ ... ]])'
part go your output) using a few optimizations.
A last thing. Is there a reason your helper function includes superfluous parentheses? This seems sufficient
sT = @(x)num2str(T(x),17);
or
sT = @(x)sprintf('%.17g',T(x));
Note that num2str
only converts to four decimal places by default. int2str
(or %d
should be used if T(x)
is always an integer).