Error using \ .Matrix dimensions must agree problem

9 vues (au cours des 30 derniers jours)
Mesut Hocaoglu
Mesut Hocaoglu le 23 Mai 2020
Commenté : Image Analyst le 9 Avr 2021
% Condenser and hated fluid Data
UAc = 30600 ; %W/K
mc = 6.8 ; %kg/s
% Evaporator Data
UAe = 26500 ; %W/K
me = 7.6 ; %kg/s
%input data
ta = input('Input Temperature at evaporator inlet water(celsius),ta : ');
tb = input('Input Temperature at condensor inlet water(celsius),tb : ');
cp = input('Specific heat capacity (kJ/kgK),cp : ');
tol = 0.0001 %tol is converge tolerance
%guess
te= 5;
tc= 45;
qe= 160;
qc= 190;
P = 40;
iter = 0 ; %iteration
xnew = [te;tc;qe;qc;P];
xold = zeros(size(xnew));
while norm(xnew- xold) > tol
iter = iter+1;
xold = xnew ;
%update te,tc,qe,qc,P
te= xold(1);
tc= xold(2);
qe= xold(3);
qc= xold(4);
P = xold(5);
%Create equations for differrential;
%Refigeration capacity
f1 = 239.5+(10.073*te)-(0.109*(te^2))-(3.41*tc)-(0.0025*(tc^2))-(0.203*te*tc)+(0.0082*(te^2)*tc)+(0.0013*te*(tc^2))-(0.000080005*(te^2)*(tc^2))- qe;
%Power required by compressor
f2 = -2.634-(0.3081*te)-(0.00301*(te^2))+(1.066*tc)-(0.00528*(tc^2))-(0.0011*te*tc)-(0.000306*(te^2)*tc)+(0.000567*te*(tc^2))-(0.0000031*(te^2)*(tc^2))-P;
%Evaporator heat transfer rate
f3 = me*cp*(ta-te)*(1-exp(UAe/(me*cp*1000)))- qe;
%Condensor heat transfer rate
f4 = mc*cp*(tc-tb)*(1-exp(UAe/(mc*cp*1000)))- qc;
%Energy balance
f5 =P+qe-qc;
% Newton raphson method
%diff f1
f1te = diff(f1,te); % differential f1 by te
f1tc = diff(f1,tc); % differential f1 by tc
f1qe = diff(f1,qe); % differential f1 by qe
f1qc = diff(f1,qc); % differential f1 by qc
f1P = diff(f1,P); % differential f1 by P
%diff f2
f2te = diff(f2,te); % differential f2 by te
f2tc = diff(f2,tc); % differential f2 by tc
f2qe = diff(f2,qe); % differential f2 by qe
f2qc = diff(f2,qc); % differential f2 by qc
f2P = diff(f2,P); % differential f2 by P
%diff f3
f3te = diff(f3,te); % differential f3 by te
f3tc = diff(f3,tc); % differential f3 by tc
f3qe = diff(f3,qe); % differential f3 by qe
f3qc = diff(f3,qc); % differential f3 by qc
f3P = diff(f3,P); % differential f3 by P
%diff f4
f4te = diff(f4,te); % differential f4 by te
f4tc = diff(f4,tc); % differential f4 by tc
f4qe = diff(f4,qe); % differential f4 by qe
f4qc = diff(f4,qc); % differential f4 by qc
f4P = diff(f4,P); % differential f4 by P
%diff f5
f5te = diff(f5,te); % differential f5 by te
f5tc = diff(f5,tc); % differential f5 by tc
f5qe = diff(f5,qe); % differential f5 by qe
f5qc = diff(f5,qc); % differential f5 by qc
f5P = diff(f5,P); % differential f5 by P
J = [f1te f1tc f1qe f1qc f1P;f2te f2tc f2qe f2qc f2P;f3te f3tc f3qe f3qc f3P;f4te f4tc f4qe f4qc f4P;f5te f5tc f5qe f5qc f5P];
xnew = xold - J\[te;tc;qe;qc;P];
disp(fprintf('iter=%6.5f, te=%6.5f, tc=%6.5f, qe=%6.5f, qc=%6.5f, P=%6.5f', iter));
disp(xnew)
end
I have an error at xnew = xold - J\[te;tc;qe;qc;P]; this line.
error code is :
Error using \
Matrix dimensions must agree.
Error in unt (line 90)
xnew = xold - J\[te;tc;qe;qc;P];
I have ta, tb values and I want to calculate te tc qe and P at less than 0.1 percent error. Also this is my homework question.
------------------------------------------------------------------------------------------------------------
Q3. (P6.17). A refrigeration plant that operates on the cycle shown in Fig. 6-27 serves as a water chiller. Data on the individual components are as follows:
𝑈𝐴 = {30,600 𝑊/𝐾 𝑒𝑣𝑎𝑝𝑜𝑟𝑎𝑡𝑜𝑟 26,500 𝑊/𝐾 𝑐𝑜𝑛𝑑𝑒𝑛𝑠𝑒𝑟}
𝑅𝑎𝑡𝑒 𝑜𝑓 𝑤𝑎𝑡𝑒𝑟 𝑓𝑙𝑜𝑤 = {6.8 𝑘𝑔/𝑠 𝑒𝑣𝑎𝑝𝑜𝑟𝑎𝑡𝑜𝑟 7.6 𝑘𝑔/𝑠 𝑐𝑜𝑛𝑑𝑒𝑛𝑠𝑒𝑟}
The refrigeration capacity of the compressor as a function of the evaporating and condensing temperatures te and tc, respectively, is given by the equation developed in Prob. 4.9.
𝑞𝑒[𝑘𝑊] = 239.5 + 10.073𝑡𝑒 − 0.109𝑡𝑒 2 − 3.41𝑡𝑐 − 0.00250𝑡𝑐 2 − 0.2030𝑡𝑒𝑡𝑐 + 0.00820𝑡𝑒 2𝑡𝑐 + 0.0013𝑡𝑒𝑡𝑐 2 − 0.000080005𝑡𝑒 2𝑡𝑐 2
The compression power is expressed by equation
𝑃[𝑘𝑊] = −2.634 − 0.3081𝑡𝑒 − 0.00301𝑡𝑒 2 + 1.066𝑡𝑐 − 0.00528𝑡𝑐 2 − 0.0011𝑡𝑒𝑡𝑐 − 0.000306𝑡𝑒 2𝑡𝑐 + 0.000567𝑡𝑒𝑡𝑐 2 + 0.0000031𝑡𝑒 2𝑡𝑐 2
The condenser must reject the energy added in both the evaporator and the compressor. Determine the values of 𝑡𝑒, 𝑡𝑐, 𝑞𝑒 and P for the following combinations of inlet water temperatures:
Evaporator inlet water ta, oC 10 15 10 15
Condenser inlet water tb, oC 25 25 30 30
Continue iterations until all variables change by an absolute value less than 0.1 percent during an iteration.
------------------------------------------------------------------------------------------------------------
I tried to use
xnew = xold - J.\[te;tc;qe;qc;P];
but it doesn't work.
How can I solve this error? You can recommend another code also.
  1 commentaire
Tom Misaki
Tom Misaki le 8 Avr 2021
Hi Mesut, Could you please post the correct code for this question? I will appreciate your support.

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 24 Mai 2020
See the error section in the FAQ: https://matlab.fandom.com/wiki/FAQ#Error_Messages
  2 commentaires
Tom Misaki
Tom Misaki le 9 Avr 2021
Would you mind to post here the correct code for this question? I will appreciate your support.
Image Analyst
Image Analyst le 9 Avr 2021
I didn't fix it. When I ran it just now I noticed that the f's are all scalars, so the diff()'s are all empty. So J is empty and you get an error. Sorry, I don't have the answer for your homework problem. You'll just have to figure out what the f's should be.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Numerical Integration and Differential Equations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by