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

9 views (last 30 days)
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 Comments
Ameer Hamza
Ameer Hamza on 5 May 2020
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.

Sign in to comment.

Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!