Solve system of equations with 4 + 2N equations

조회 수: 3 (최근 30일)
letoppina
letoppina 2021년 3월 17일
댓글: Alan Stevens 2021년 3월 20일
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?

채택된 답변

Alan Stevens
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
letoppina
letoppina 2021년 3월 20일
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 2021년 3월 20일
You will need equations that describe them.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by