Solve system of equations with 4 + 2N equations
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
letoppina
am 17 Mär. 2021
Kommentiert: Alan Stevens
am 20 Mär. 2021
Hello, I would like to implement on matlab different systems of equations, all connected to one another. I have a total of 4 + 2N equations (2 equations at the 2 edges of my geometry and 2N equations - the internal parts of my geometry).
Here is an example of the code (not working), just to give you an idea of what I mean:
%unknowns
Qm = zeros(Ntot,1);
T = zeros(Ntot,1);
Qc = 0;
Qh = 0;
for ii=1:N
%system 1
Qm(1) = -Qc + q0 - Pc - qw/2;
T(1) = T0 - Rc*Qc;
%system i
T(ii) - T(ii-1) = R1/Nc*q0 - R1/Nc*Qm1;
T(ii) - Rg0/Nc*Qm(ii-1) + Rg0/Nc*Qm(ii) = T0;
%system N
Qh - Qm(N) = Ph - q0 + qw/2;
T(N) - T0 = Rh0*Qh;
end
How can I implement this on Matlab?
0 Kommentare
Akzeptierte Antwort
Alan Stevens
am 17 Mär. 2021
Not entirely clear to me what you want, but perhaps something like the following, where the edge equations are taken outside the loop:
% Arbitrary data
Qc = 0;
Qh = 0;
q0 = 1000;
Pc = 1;
Ph = 1;
qw = 1;
Rc = 1;
R1 = 1;
Rg0 = 1;
Rh0 = 1;
Nc = 1;
T0 = 10;
Ntot = 10;
%unknowns
Qm = zeros(Ntot,1);
T = zeros(Ntot,1);
%system 1
Qm(1) = -Qc + q0 - Pc - qw/2;
T(1) = T0 - Rc*Qc;
for ii=2:Ntot-1
%system i
T(ii) = T(ii-1) + R1/Nc*q0 - R1/Nc*Qm(ii-1);
Qm(ii) = Qm(ii-1) + (T0 - T(ii))*Nc/Rg0;
end
%system N
Qm(Ntot) = Qh - (Ph - q0 + qw/2);
T(Ntot) = T0 + Rh0*Qh;
plot(Qm,T),grid
2 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!