Gettting Error: In an assignment A(I) = B, the number of elements in B and I must be the same.

Hi Everyone,
I'm new to MATLAB, and I'm trying to use it to solve a system of 9 equations with 9 unknown variables. I keep getting the following error, and I haven't been able to figure out why:
Warning: Explicit solution could not be found.
> In solve at 169
In HWK3 at 207
In an assignment A(I) = B, the number of elements in B and I must be the same.
Any help would be very much appreciated!
MY CODE:
--------------------------
clear
clc
%DECLARE CONSTANTS
Tair_in= 299.15; %Given Tair_int at 26C
Hint= 1.8; %Given Hint at 1.8W/m^2K
%EAST WALL
Ae= 25; %Given Area E of 25 m^2
dXconcrete= 0.12; %Given thickness of 12cm for concrete (m)
Kconcrete= 0.5; %Given conductivity for concrete (W/mK)
Dconcrete= 2500; %Given density of concrete (kg/m^3)
CPconcrete= 1000; %Given specific capacity for concrete (J/kgK)
dXinsulation= 0.04; %Given thickness of 4cm for insulation (m)
Kinsulation= 0.008; %Given conductivity for insulation (W/mK)
Dinsulation= 50; %Given density of insulation (kg/m^3)
CPinsulation= 800; %Given specific capacity for insulation (J/kgK)
%NORTH WALL
An= 25; %Given Area N of 25 m^2
dXnorth= 0.005;%Given thickness of 0.5cm for N wall
Kn= 0.8; %Given conductivity of 0.8 for N wall (W/mK)
Dn= 2500; %Given density of glass (kg/m^3)
CPn= 1000; %Given specific capacity for glass (J/kgK)
%INTERNAL SURFACES
Ai= 250; %Given Area Internal of 250 m^2
dXi= 0.02; %Given thickness of 2cm for HALF of internal surfaces (adiabatic)
Ki= 0.5; %Given conductivity of 0.5 for internal surfaces (W/mK)
Di= 800; %Given density of internal surfaces (kg/m^3)
CPi= 1000; %Given specific capacity for internal surfaces (J/kgK)
%VIEW FACTORS
Fe_g= 0.5; %View factor between E facade and ground
Fe_s= 0.5; %View factor between E facade and sky
Fei_i= 0.9; %View factor between E internal and internal surfaces
Fe_n= 0.1; %View factor between E internal and N internal surface
Fn_s= 0.5; %View factor between N facade and sky
Fn_g= 0.5; %View factor between N facade and ground
Fn_e= 0.1; %View factor between N internal and E internal surface
Fi_n= 0.09; %View factor between internal surfaces and N internal surface
Fi_e= 0.09; %View factor between internal surfaces and E internal surface
Fn_i= 0.9; %View factor between N internal surface and internal surfaces
%RADIATIVE PROPERTIES
%LONG-WAVE
EMground= 0.9; %Emissivity of ground
EMsky= 1; %Emissivity of sky
EMlw_n= 0.95; %Emissivity of North wall for LW radiation
ABlw_n= 0.95; %Absoprtivity of North wall for LW radiation
EMlw_i= 0.95; %Emissivity of Internal surfaces for LW radiation
ABlw_i= 0.95; %Absoprtivity of Internal surfaces for LW radiation
EMlw_e= 0.95; %Emissivity of East wall for LW radiation
ABlw_e= 0.95; %Absoprtivity of East wall for LW radiation
%SHORT-WAVE
ABsw_e= 0.6; %Absorptivity of East wall for SW radiation
ABsw_i= 0.6; %Absorptivity of Internal surfaces for SW radiation
ABsw_n= 0.6; %Absorptivity of North wall for SW radiation
SB= 5.670373E-8; %Stefan-Boltzmann constant
Tglass= 0.74; %Calculated transmissivity of N glass (given absorptivity and reflectivity)
Vspace= 250; %Calculate volume of space to be 250 m^3
%AIR PROPERTIES
Achanges= 1; %Given ACH
CPair= 1000; %Given Cp of 1000 J/kgK for air
Dair= 1.2; %Given density of air (kg/m^3)
%WEATHER DATA
%External Convection Coefficients
Hn= [6.3 6.2 6.0 5.9 6.5 5.9 6.0 6.5 6.8 6.9 6.6 6.5 6.6 6.6 6.8 6.9 6.9 6.6 6.6 6.6 6.9 6.6 6.8 6.8 6.3 6.2 6.0 5.9 6.5 5.9 6.0 6.5 6.8 6.9 6.6 6.5 6.6 6.6 6.8 6.9 6.9 6.6 6.6 6.6 6.9 6.6 6.8 6.8];
He= [6.3 6.2 6.0 5.9 6.5 5.9 6.0 6.5 6.8 6.9 6.6 6.5 6.6 10.8 6.8 12.2 12.2 10.8 6.6 10.8 12.2 10.8 11.5 11.5 6.3 6.2 6.0 5.9 6.5 5.9 6.0 6.5 6.8 6.9 6.6 6.5 6.6 10.8 6.8 12.2 12.2 10.8 6.6 10.8 12.2 10.8 11.5 11.5];
%Given Temperatures
Tsky= [290.0 290.9 289.3 291.0 291.0 290.2 290.2 292.1 293.2 295.4 295.7 296.1 296.7 297.5 297.0 296.6 296.6 296.3 294.9 293.2 292.1 292.2 291.1 289.6 290.0 290.9 289.3 291.0 291.0 290.2 290.2 292.1 293.2 295.4 295.7 296.1 296.7 297.5 297.0 296.6 296.6 296.3 294.9 293.2 292.1 292.2 291.1 289.6];
Tground= [299.9 299.3 298.8 298.8 298.8 298.2 298.8 299.3 301.0 303.8 304.9 306.5 307.6 308.2 308.8 308.8 308.8 307.6 306.5 305.4 303.8 302.6 301.5 299.9 299.9 299.3 298.8 298.8 298.8 298.2 298.8 299.3 301.0 303.8 304.9 306.5 307.6 308.2 308.8 308.8 308.8 307.6 306.5 305.4 303.8 302.6 301.5 299.9];
Tair_out= [299.9 299.3 298.8 298.8 298.8 298.2 298.8 299.3 301.0 303.8 304.9 306.5 307.6 308.2 308.8 308.8 308.8 307.6 306.5 305.4 303.8 302.6 301.5 299.9 299.9 299.3 298.8 298.8 298.8 298.2 298.8 299.3 301.0 303.8 304.9 306.5 307.6 308.2 308.8 308.8 308.8 307.6 306.5 305.4 303.8 302.6 301.5 299.9];
%Qtotalsolar from given DIR and DIF components
Qsol_n= [0.0 0.0 0.0 0.0 0.0 0.0 19.5 96.1 118.2 169.6 187.0 180.2 195.2 208.7 156.3 163.0 115.2 121.1 83.4 4.9 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 19.5 96.1 118.2 169.6 187.0 180.2 195.2 208.7 156.3 163.0 115.2 121.1 83.4 4.9 0.0 0.0 0.0 0.0];
Qsol_e= [0 0 0 0 0 0 23 189 391 572 408 398 212 209 156 163 115 93 30 3 0 0 0 0 0 0 0 0 0 0 23 189 391 572 408 398 212 209 156 163 115 93 30 3 0 0 0 0];
%Initialization of symbolic variables (to solve)
syms EAST0 EAST1 EAST2 EAST3 EAST4 INT0 INT1 NORTH0 QHVAC;
%CALCULATE MASS FLOW RATE OF AIR
m= 1.2*Achanges*Vspace/3600;
%Initialization of tau ("old") arrays, setting temp of 28C (301.15K) for all surface
%and internal nodes
a_oldEAST0temp= 301.15;
b_oldEAST1temp= 301.15;
c_oldEAST2temp= 301.15;
d_oldEAST3temp= 301.15;
e_oldEAST4temp= 301.15;
f_oldINT0temp= 301.15;
g_oldINT1temp= 301.15;
h_oldNORTH0temp= 301.15;
%Initialization of tau+delta tau ("new") arrays
a_newEAST0temps=zeros(1,48);
b_newEAST1temps=zeros(1,48);
c_newEAST2temps=zeros(1,48);
d_newEAST3temps=zeros(1,48);
e_newEAST4temps=zeros(1,48);
f_newINT0temps=zeros(1,48);
g_newINT1temps=zeros(1,48);
h_newNORTH0temps=zeros(1,48);
i_QHVAC=zeros(1,48); %Initialize Qhvac array
LoopCount = 0; %Loop counter
%SYSTEM OF EQUATIONS
for j=1:48
%CALCULATE H (NORTH INTERNAL)
Hn_int = (1.823*abs(Tair_in-h_oldNORTH0temp)^0.291/(2.5^0.1));
%EQ1- INTERNAL NODE NORTH0
Qsolar = Qsol_n(j)*An*ABsw_n;
Qlwsky = An*Fn_s*EMsky*EMlw_n*SB*((Tsky(j)^4)-h_oldNORTH0temp);
Qlwgr = An*Fn_g*EMground*EMlw_n*SB*((Tground(j)^4)-h_oldNORTH0temp);
Qlwint = An*Fn_i*EMlw_n*EMlw_i*SB*((f_oldINT0temp^4)-(h_oldNORTH0temp^4));
Qlwe = An*Fn_e*EMlw_n*EMlw_e*SB*((e_oldEAST4temp^4)-(h_oldNORTH0temp^4));
Qextconv = An*Hn(j)*(Tair_out(j)-h_oldNORTH0temp);
Qintconv = An*Hn_int*(Tair_in-h_oldNORTH0temp);
EnergyStorage = An*Dn*CPn*dXnorth*((NORTH0-h_oldNORTH0temp)/3600);
EQ1 = Qsolar+Qlwsky+Qlwgr+Qlwint+Qlwe+Qextconv+Qintconv-EnergyStorage;
%CALCULATE H (EAST INTERNAL)
He_int = (1.823*abs(Tair_in-e_oldEAST4temp)^0.291/(2.5^0.1));
%EQ2 - SURFACE NODE EAST4
Qsolar = Qsol_n(j)*An*Tglass*((Ae*ABsw_e)/((Ae*ABsw_e)+(An*(ABsw_n+Tglass))+(Ai*ABsw_i)));
Qlwint = Ae*Fei_i*EMlw_e*EMlw_i*SB*((INT0^4)-(EAST4^4));
Qlwn = Ae*Fe_n*EMlw_e*EMlw_n*SB*((NORTH0^4)-(EAST4^4));
Qintconv = Ae*He_int*(Tair_in-EAST4);
Qcond = (Kinsulation/(dXinsulation/2))*(EAST4-e_oldEAST4temp);
EQ2 = Qsolar+Qlwint+Qlwn+Qintconv-Qcond;
%EQ3 - INTERNAL NODE EAST3
Qcond_4to3 = Ae*(Kinsulation/(dXinsulation/2))*(e_oldEAST4temp-d_oldEAST3temp);
Qcond_3to2 = Ae*(Kinsulation/(dXinsulation/2))*(d_oldEAST3temp-c_oldEAST2temp);
EnergyStorage = Ae*Dinsulation*CPinsulation*dXinsulation*((EAST3-d_oldEAST3temp)/3600);
EQ3 = Qcond_4to3-Qcond_3to2-EnergyStorage;
%EQ4 - SURFACE NODE EAST2
Qcond_3to2 = Ae*(Kinsulation/(dXinsulation/2))*(EAST3-EAST2);
Qcond_2to1 = Ae*(Kconcrete/(dXconcrete/2))*(EAST2-EAST1);
EQ4 = Qcond_3to2-Qcond_2to1;
%EQ5 - INTERNAL NODE EAST1
Qcond_2to1 = Ae*(Kconcrete/(dXconcrete/2))*(c_oldEAST2temp-b_oldEAST1temp);
Qcond_1to0 = Ae*(Kconcrete/(dXconcrete/2))*(b_oldEAST1temp-a_oldEAST0temp);
EnergyStorage = Ae*Dconcrete*CPconcrete*dXconcrete*((EAST1-b_oldEAST1temp)/3600);
EQ5 = Qcond_2to1-Qcond_1to0-EnergyStorage;
%EQ6 - SURFACE NODE EAST0
Qsolar = Qsol_e(j)*Ae*ABsw_e;
Qlwsky = Ae*Fe_s*EMsky*EMlw_e*SB*((Tsky(j)^4)-(EAST0^4));
Qlwgr = Ae*Fe_g*EMground*EMlw_e*SB*((Tground(j)^4)-(EAST0^4));
Qextconv = Ae*He(j)*(Tair_out(j)-EAST0);
Qcond_1to0 = Ae*(Kconcrete/(dXconcrete/2))*(EAST1-EAST0);
EQ6 = Qsolar+Qlwsky+Qlwgr+Qextconv+Qcond_1to0;
%EQ7 - SURFACE NODE INT0
Qsolar = Qsol_n(j)*An*Tglass*((Ai*ABsw_i)/((Ai*ABsw_i)+(An*(ABsw_n+Tglass))+(Ae*ABsw_e)));
Qlwn = Ai*Fi_n*EMlw_i*EMlw_n*SB*((NORTH0^4)-(INT0^4));
Qlwe = Ai*Fi_e*EMlw_i*EMlw_e*SB*((EAST4^4)-(INT0^4));
Qintconv = Ai*1.8*(Tair_in-INT0);
Qcond_1to0 = Ai*(Ki/(dXi/2))*(INT1-INT0);
EQ7 = Qsolar+Qlwn+Qlwe+Qintconv-Qcond_1to0;
%EQ8 - INTERNAL NODE INT1
Qcond_1to0 = Ai*(Ki/(dXi/2))*(g_oldINT1temp-f_oldINT0temp);
EnergyStorage = Ai*Di*CPi*dXi*((INT0-f_oldINT0temp)/3600);
EQ8 = EnergyStorage-Qcond_1to0;
%EQ9 - QHVAC
EQ9= -QHVAC+(Ae*He_int*(EAST4-Tair_in))+(An*Hn_int*(NORTH0-Tair_in))+(m*CPair*(Tair_out(j)-Tair_in));
%SOLVE SYSTEM OF EQUATIONS
[a_newEAST0temps(j), b_newEAST1temps(j), c_newEAST2temps(j), d_newEAST3temps(j), e_newEAST4temps(j), f_newINT0temps(j), g_newINT1temps(j), h_newNORTH0temps(j), i_QHVAC(j)] = solve(EQ1,EQ2,EQ3,EQ4,EQ5,EQ6,EQ7,EQ8,EQ9);
%Set Tau values to be Tau+deltaTau values (just calculated)
a_oldEAST0temp= a_newEAST0temps(j);
b_oldEAST1temp= b_newEAST1temps(j);
c_oldEAST2temp= c_newEAST2temps(j);
d_oldEAST3temp= d_newEAST3temps(j);
e_oldEAST4temp= e_newEAST4temps(j);
f_oldINT0temp= f_newINT0temps(j);
g_oldINT1temp= g_newINT1temps(j);
h_oldNORTH0temp= h_newNORTH0temps(j);
LoopCount=LoopCount+1
end
nodeTemps=[a_newEAST0temps; b_newEAST1temps; c_newEAST2temps; d_newEAST3temps; e_newEAST4temps; f_newINT0temps; g_newINT1temps; h_newNORTH0temps; i_QHVAC;]'

Answers (1)

solve() is deciding there is no solution that it can find, so it is returning the empty set, 0 elements long. You cannot store 0 elements in a space reserved for 1 element (such as a_newEAST0temps(j) ) as that is a size mismatch.
Use the single-output form of solve() to get a structure array out. Test to see if the result was empty. If not, assign the appropriate fields of the structure array to the appropriate variables, and otherwise ... well, what do you want to do in the case when no solution could be found?

Tags

Asked:

on 23 Oct 2012

Community Treasure Hunt

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

Start Hunting!