Azzera filtri
Azzera filtri

Solve system of equations with 4 + 2N equations

1 visualizzazione (ultimi 30 giorni)
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?

Risposta accettata

Alan Stevens
Alan Stevens il 17 Mar 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 Commenti
letoppina
letoppina il 20 Mar 2021
Thanks, it was very sueful. However, Qc and Qh are also unknown variables. How can I initiate them without giving them a fixed value?
Alan Stevens
Alan Stevens il 20 Mar 2021
You will need equations that describe them.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by