Getting matrix multiplication dimension error when using parfor, but not when using for loop

조회 수: 9 (최근 30일)
Hi,
I am trying to solve a system of equations with fsolve, for different input values. Naturally, I put my fsolve inside a for loop.
When I run it like this, everything is fine. When I run it with a parfor instead of for, I get the error:
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number
of rows in the second matrix. To perform elementwise multiplication, use '.*'.
Here is the relevant part of my code:
eq_system = @(x, Voltage) build_equation_sytem(x, app.incidence_matrix, app.components, Voltage);
V = [V_start : V_step : V_end];
I = zeros(1 , length(V));
parfor i = 1:length(V)
sol = fsolve(@(x) eq_system(x, V(i)), x0, options);
I(i) = sol(b);
end
The only thing related to this is a post where people say one shouldn't access global variables inside a parfor. I made sure that my build_eq_system function does not call any global variables, so this can't be the case here. Any ideas?
  댓글 수: 3
Ameer Hamza
Ameer Hamza 2020년 5월 5일
The problem is coming from the definition of build_equation_sytem. Somewhere, matrix multiplication is causing an error. Can you share the code of this function? Also, share some value for the input variables. It seems that you are using this in the app-designer. You can share a script with suitable values of input variables.
Bob Roger
Bob Roger 2021년 8월 5일
Did you solve your problem? I have the same issue...
Does fsolve contain global variables?

댓글을 달려면 로그인하십시오.

답변 (0개)

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by