Error in assignment in parfor
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hello everyone !
I am struggling with a piece of code.
x = sym('x', [1,H]);
eqm=gamma*p_isa.*x.^2==(WoS/C_D0)*[(ToW_sl*0.76*(0.907+0.262*(abs(x-0.5)).^1.5).*(rho_isa/rho_ssl).^0.7)-sqrt((ToW_sl*0.76*(0.907+0.262*(abs(x-0.5)).^1.5).*(rho_isa/rho_ssl).^0.7).^2-4*K*C_D0)];
eqM=gamma*p_isa.*x.^2==(WoS/C_D0)*[(ToW_sl*0.76*(0.907+0.262*(abs(x-0.5)).^1.5).*(rho_isa/rho_ssl).^0.7)+sqrt((ToW_sl*0.76*(0.907+0.262*(abs(x-0.5)).^1.5).*(rho_isa/rho_ssl).^0.7).^2-4*K*C_D0)];
parfor i=1:H
M_rmin(i)=double(vpasolve(eqm(i),x(i),M_min(i)));
M_rmax(i)=double(vpasolve(eqM(i),x(i),M_max(i)));
V_rmax(i)=M_rmax(i)*c(i);
V_rmin(i)=M_rmin(i)*c(i);
end
I defined 2 vector equations, each row corresponding to a given altitude. All the coefficients have been computed before and the only thing I change is the altitude step, hence H which is the length of my altitude vector. The code works fine for high steps (100m is ok) but i need to make it work with a smaller step, so I tried 10m. The thing is I get this error at the line of parfor : In an assignment A(:) = B, the number of elements in A and B must be the same.
The loop stopped at some point. I checked all the dimensions, they are all matching. I solved the equation outside the loop for a rank higher than the one at which it had stopped and I get a result, so this should work.
Could you help me ?
Thanks !
0 Commenti
Risposte (2)
Walter Roberson
il 27 Nov 2015
You did not happen to provide any sample values, and it is not clear from your posting which variable is the "step".
Generally speaking, you could run into the problem you did if vpasolve() were to return something other than 1 result. That might occur if it returned no results (no solution found); for equations that it determines to be polynomials it can also return multiple (more than 1) value.
0 Commenti
Flavien Saenz Molina
il 27 Nov 2015
Modificato: Flavien Saenz Molina
il 27 Nov 2015
1 Commento
Walter Roberson
il 27 Nov 2015
Do you get the same error if you use "for" instead of "parfor" ?
I recommend,
parfor i=1:H
t_M_rmin = double(vpasolve(eqm(i),x(i),M_min(i)));
t_M_rmax = double(vpasolve(eqM(i),x(i),M_max(i)));
if length(t_M_rmin) ~= 1 || length(t_M) ~= 1
fprintf('iteration %d failed, received %d results for rmin and %d results for rmax\n', i, length(t_M_rmin), length(t_M_rmax));
M_rmin(i) = nan;
M_rmax(i) = nan;
V_rmax(i) = nan;
V_rmin(i) = nan;
else
M_rmin(i) = t_M_rmin;
M_rmax(i) = t_M_rmax;
V_rmax(i) = t_M_rmax * c(i);
V_rmin(i) = t_M_rmin(i) * c(i);
end
end
Vedere anche
Categorie
Scopri di più su Parallel for-Loops (parfor) in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!