Error in assignment in parfor
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Walter Roberson
2015-11-27
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 个评论
Flavien Saenz Molina
2015-11-27
编辑:Flavien Saenz Molina
2015-11-27
1 个评论
Walter Roberson
2015-11-27
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!