Parfor transparency error when using subs to evaluate a symbolic expression.

4 Ansichten (letzte 30 Tage)
Good Day, Everyone.
My code generates trasparency error at the highlighted (bold text) penultimate line: this_S=double(subs(S_3FA'));
Error using sym/subs (line 75)
Transparency violation error.
See Parallel Computing Toolbox documentation about Transparency
Can you help me fix it? Thank you!
Fardad
********************************************************************
parfor nn=1:2
Nof_FA=3;
Aorig=10;
Nseg_full=10*Nof_FA;
Lamb=12;
ii=1;
jj=2;
ll=3;
alpha1 = ii*pi;
alpha2 = jj*pi;
alpha3 = ll*pi;
kk=1;
mm=2;
TR1 = (kk+2.56);
TR2 = (mm+2.56);
Nseg1=floor((Nseg_full/(TR1/3.56)));
Nseg2=floor((Nseg_full/(TR2/3.56)));
a = sym('a'); b1 = sym('b1'); iinv = sym('iinv'); q1 = sym('q1'); q2 = sym('q2'); f = sym('f'); t1 = sym('t1');
q3 = sym('q3');
M1_0=a*(1-exp(-TR1/t1))/(1-exp(-TR1/t1)*cos(b1*alpha1)*exp(f*TR1/Lamb))*(1-(1-q1*iinv));
M1_end=a*(1-exp(-TR1/t1))/(1-exp(-TR1/t1)*cos(b1*alpha1)*exp(f*TR1/Lamb))*(1-(1-q1*iinv)*(exp(-TR1/t1)*cos(b1*alpha1)*exp(f*TR1/Lamb))^(Nseg1/Nof_FA));
M2_0=a*(1-exp(-TR2/t1))/(1-exp(-TR2/t1)*cos(b1*alpha2)*exp(f*TR2/Lamb))*(1-(1-q2*iinv));
M2_end=a*(1-exp(-TR2/t1))/(1-exp(-TR2/t1)*cos(b1*alpha2)*exp(f*TR2/Lamb))*(1-(1-q2*iinv)*(exp(-TR2/t1)*cos(b1*alpha2)*exp(f*TR2/Lamb))^(Nseg2/Nof_FA));
TR3 = (nn+2.56)/1000;
Nseg3=floor((Nseg_full/(TR3/3.56))/1000);
M3_0=a*(1-exp(-TR3/t1))/(1-exp(-TR3/t1)*cos(b1*alpha3)*exp(f*TR3/Lamb))*(1-(1-q3*iinv));
M3_end=a*(1-exp(-TR3/t1))/(1-exp(-TR3/t1)*cos(b1*alpha3)*exp(f*TR3/Lamb))*(1-(1-q3*iinv)*(exp(-TR3/t1)*cos(b1*alpha3)*exp(f*TR3/Lamb))^(Nseg3/Nof_FA));
[Q1, Q2, Q3]=solve(...
M1_0==iinv*M3_end, M2_0==iinv*M1_end, M3_0==iinv*M2_end,q1,q2,q3);
M1=@(t1,b1,f,a,iinv)a*(1-exp(-TR1/t1))/(1-exp(-TR1/t1)*cos(b1*alpha1)*exp(f*TR1/Lamb))*(1-(1-Q1*iinv)*(exp(-TR1/t1)*cos(b1*alpha1)*exp(f*TR1/Lamb)).^(1:Nseg1/Nof_FA));
M1=subs(M1);
M2=@(t1,b1,f,a,iinv)a*(1-exp(-TR2/t1))/(1-exp(-TR2/t1)*cos(b1*alpha2)*exp(f*TR2/Lamb))*(1-(1-Q2*iinv)*(exp(-TR2/t1)*cos(b1*alpha2)*exp(f*TR2/Lamb)).^(1:Nseg2/Nof_FA));
M2=subs(M2);
M3=@(t1,b1,f,a,iinv)a*(1-exp(-TR3/t1))/(1-exp(-TR3/t1)*cos(b1*alpha3)*exp(f*TR3/Lamb))*(1-(1-Q3*iinv)*(exp(-TR3/t1)*cos(b1*alpha3)*exp(f*TR3/Lamb)).^(1:Nseg3/Nof_FA));
M3=subs(M3);
Sint_1=@(t1,b1,f,a,iinv)M1*sin(b1*alpha1);
Sint_1=subs(Sint_1);
Sint_2=@(t1,b1,f,a,iinv)M2*sin(b1*alpha2);
Sint_2=subs(Sint_2);
Sint_3=@(t1,b1,f,a,iinv)M3*sin(b1*alpha3);
Sint_3=subs(Sint_3);
S_3FA=[Sint_1 Sint_2 Sint_3];
a=Aorig/sqrt(Nof_FA); b1=1; iinv=-1; t1=1.25; f=6.5/60;
this_S=double(subs(S_3FA'));
end

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 14 Nov. 2021
Bearbeitet: Walter Roberson am 14 Nov. 2021
parfor nn=1:2
Nof_FA=3;
Aorig=10;
Nseg_full=10*Nof_FA;
Lamb=12;
ii=1;
jj=2;
ll=3;
alpha1 = ii*pi;
alpha2 = jj*pi;
alpha3 = ll*pi;
kk=1;
mm=2;
TR1 = (kk+2.56);
TR2 = (mm+2.56);
Nseg1=floor((Nseg_full/(TR1/3.56)));
Nseg2=floor((Nseg_full/(TR2/3.56)));
a = sym('a'); b1 = sym('b1'); iinv = sym('iinv'); q1 = sym('q1'); q2 = sym('q2'); f = sym('f'); t1 = sym('t1');
q3 = sym('q3');
M1_0=a*(1-exp(-TR1/t1))/(1-exp(-TR1/t1)*cos(b1*alpha1)*exp(f*TR1/Lamb))*(1-(1-q1*iinv));
M1_end=a*(1-exp(-TR1/t1))/(1-exp(-TR1/t1)*cos(b1*alpha1)*exp(f*TR1/Lamb))*(1-(1-q1*iinv)*(exp(-TR1/t1)*cos(b1*alpha1)*exp(f*TR1/Lamb))^(Nseg1/Nof_FA));
M2_0=a*(1-exp(-TR2/t1))/(1-exp(-TR2/t1)*cos(b1*alpha2)*exp(f*TR2/Lamb))*(1-(1-q2*iinv));
M2_end=a*(1-exp(-TR2/t1))/(1-exp(-TR2/t1)*cos(b1*alpha2)*exp(f*TR2/Lamb))*(1-(1-q2*iinv)*(exp(-TR2/t1)*cos(b1*alpha2)*exp(f*TR2/Lamb))^(Nseg2/Nof_FA));
TR3 = (nn+2.56)/1000;
Nseg3=floor((Nseg_full/(TR3/3.56))/1000);
M3_0=a*(1-exp(-TR3/t1))/(1-exp(-TR3/t1)*cos(b1*alpha3)*exp(f*TR3/Lamb))*(1-(1-q3*iinv));
M3_end=a*(1-exp(-TR3/t1))/(1-exp(-TR3/t1)*cos(b1*alpha3)*exp(f*TR3/Lamb))*(1-(1-q3*iinv)*(exp(-TR3/t1)*cos(b1*alpha3)*exp(f*TR3/Lamb))^(Nseg3/Nof_FA));
[Q1, Q2, Q3]=solve(...
M1_0==iinv*M3_end, M2_0==iinv*M1_end, M3_0==iinv*M2_end,q1,q2,q3);
M1 = a*(1-exp(-TR1/t1))/(1-exp(-TR1/t1)*cos(b1*alpha1)*exp(f*TR1/Lamb))*(1-(1-Q1*iinv)*(exp(-TR1/t1)*cos(b1*alpha1)*exp(f*TR1/Lamb)).^(1:Nseg1/Nof_FA));
M2 = a*(1-exp(-TR2/t1))/(1-exp(-TR2/t1)*cos(b1*alpha2)*exp(f*TR2/Lamb))*(1-(1-Q2*iinv)*(exp(-TR2/t1)*cos(b1*alpha2)*exp(f*TR2/Lamb)).^(1:Nseg2/Nof_FA));
M3 = a*(1-exp(-TR3/t1))/(1-exp(-TR3/t1)*cos(b1*alpha3)*exp(f*TR3/Lamb))*(1-(1-Q3*iinv)*(exp(-TR3/t1)*cos(b1*alpha3)*exp(f*TR3/Lamb)).^(1:Nseg3/Nof_FA));
Sint_1 = M1*sin(b1*alpha1);
Sint_2 = M2*sin(b1*alpha2);
Sint_3 = M3*sin(b1*alpha3);
S_3FA = [Sint_1 Sint_2 Sint_3];
a_ = Aorig/sqrt(Nof_FA); b1_ = 1; iinv_ = -1; t1_ = 1.25; f_ = 6.5/60;
this_S{nn} = double(subs(S_3FA', [a, b1, iinv, t1, f], [a_, b1_, iinv_, t1_, f_]));
end
size(this_S{1}), size(this_S{2})
ans = 1×2
27 1
ans = 1×2
24 1
Notice that the two this_S entries are different sizes. This is because M3 includes the vector (1:Nseg3/Nof_FA) but Nseg3 is related to the value of nn, so the vectors are different length for different nn values.
If you check, you will find that all of the entries in this_S are zero. This is because the expressions turn out to all involve sin(pi*b1) multiplying them, but your b1 is an integer so the sin() are all coming out as 0.
  1 Kommentar
Fardad Serry
Fardad Serry am 14 Nov. 2021
Dear Walter Roberson,
Thank you very much for taking the time to help me out. I think I understand the answer. (It certainly works; thank you).
You are correct; I am adding some code to pad the shorter array to the length of the longer one.
The sin(pi*b1) issue is a simple one I can fix.
Thakn you once more!
Fardad Serry

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by