How to make a symmetric matrix from a muxed signal in MATLAB fcn block?

8 views (last 30 days)
Hello,
I am developping a system that utilizes an MNA in simulink and need to use the fcn Block in order to calculate de correct PV tension.
I have 60 converters that are connected on a DC bus in a symmetrical format and manage to make the MNA work for a single side, but as soon as I use the variable I wrote the length of the muxed signal in for different points it gives me an error.
Here is the code I made:
function [UPV, Ibus]= fcn(IPV, Ubus)
R1 = 0.00748 / 2;
R = 0.00748;
n = length(IPV); %Logging the number of input in the muxed signal
d = floor(n/2); %Finding the end of the first side
e = d+1; %Start of the second side
G = diag(2/R * ones(n, 1)) + diag(-1/R * ones(n-1, 1), 1) + diag(-1/R * ones(n-1, 1), -1); %Making the impedance matrix.
G(1, 1) = 1/R; %Correction of the first resistor
G(d,d) = 1/R; %Correction of the resistor near the injection point on one side
G(e,d) = 0; %Removing resistor from injection point
G(d,e) = 0; %Removing resistor from injection point
G(e,e) = 1/R; %Correction of the resistor near the injection on the second side
G(n, n) = 1/R; %Correction of the last resistor
B = zeros(n, 1);
B(d) = 1;
B(e) = 1;
A = R1;
MNAG = [G -B; B' A]; %MNA matrix
sources = [IPV(:); Ubus];
resultats = MNAG \ sources;
UPV = resultats(1:n);
Ibus = 2*resultats(n+1);
In the various iterrations of this code I managed to make the programm run but all output became NaN.
  2 Comments
Divyajyoti Nayak
Divyajyoti Nayak on 17 Jul 2024
Hi @Bastien Rabaglia, could you please share the error message? It would help a lot in solving your problem.
Bastien Rabaglia
Bastien Rabaglia on 17 Jul 2024
Edited: Bastien Rabaglia on 17 Jul 2024
Certainly. Here is the message!
Error:Index expression out of bounds. Attempted to access element 0. The valid range is 1-1. Code generation does not support growing arrays via indexing except by using end+1.
More information
Function 'mono physical coupling element/MATLAB Function' (#31.223.224), line 10, column 3:
"d"
Launch diagnostic report.
Before using the floor function the error message said the value of 'd' was not an integer with a values of 0.5

Sign in to comment.

Answers (1)

Ayush
Ayush on 22 Jul 2024
Hey Bastien,
I understand that you are developing a system in Simulink that utilizes Modified Nodal Analysis (MNA) to calculate the correct PV tension for a setup with 60 converters connected to a DC bus in a symmetrical format. You are encountering an indexing error when trying to handle the muxed signal for different points.
The issue arises due to an attempt to access an element at index 0, which is not valid in MATLAB (indices start at 1). Additionally, it's important to ensure that the number of converters (n) is even for your symmetrical setup.
You can add the following lines of code to ensure this:
if mod(n, 2) ~= 0
error('The number of converters must be even.');
end
If this also doesn't help much , you can try debugging using the following steps:
  1. Check the values of n, d, and e during runtime to ensure they are valid.
  2. Verify the dimensions and values of IPV and Ubus.
Hope this helps!
Regards

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!