Search code examples
matlabparallel-processingparfor

Matlab R2017b - Transparency violation error while using parfor-loop to solve equation


This program is OK with "for", but it will prompt

“Error using syms. Transparency violation error. See Parallel Computing Toolbox documentation about Transparency. ”

when I switch to "parfor", if you could tell me how to modify this code that will be better, thank you very much.

clc
clear
close all

% parpool(4)
a = rand(5,4);
parfor i = 1:5
    syms x y
    eq1 = a(i,1)*x+a(i,2)*y==2.3;
    eq2 = a(i,3)*x+a(i,4)*y==5.1;
    x = [];y = [];
    [x,y] = vpasolve([eq1 eq2],[x y]);
    disp(x);
end

Solution

  • You simply need to replace the non-transparent version of syms that you're using with a transparent-friendly version. In other words, you need

    parfor i = 1:5
        x = sym('x');
        y = sym('y');
        ....
    end