How to make a symmetric matrix from a muxed signal in MATLAB fcn block?
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
Divyajyoti Nayak
2024-7-17
Hi @Bastien Rabaglia, could you please share the error message? It would help a lot in solving your problem.
回答(1 个)
Ayush
2024-7-22
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:
- Check the values of n, d, and e during runtime to ensure they are valid.
- Verify the dimensions and values of IPV and Ubus.
Hope this helps!
Regards
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!