Solve system of equations with 4 + 2N equations
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Alan Stevens
2021 年 3 月 17 日
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 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!