Getting matrix multiplication dimension error when using parfor, but not when using for loop
Mostrar comentarios más antiguos
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 comentarios
Radu Bors
el 5 de Mayo de 2020
Ameer Hamza
el 5 de Mayo de 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.
Bob Roger
el 5 de Ag. de 2021
Did you solve your problem? I have the same issue...
Does fsolve contain global variables?
Respuestas (0)
Categorías
Más información sobre Structural Mechanics en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!