Unable to perform assignment because the left and right sides have a different number of elements.

2 views (last 30 days)
Is there anyone who can help me with this? I cannot for the life of me figure out why this is not running. I'm trying to solve this differential equation using Euler's method, but no matter what I do I always get this error. All the matrix dimensions agree as well. The error is at the very last line.
%Declare inputs
k1 = 0.2; %W/(m^2K)
k2 = 5; %Make constant for now [1:10:]; %W/(m^2K)
k3 = 0.5; %W/(m^2K)
Ain = 0.5; %m^2
Cair = 1005; %J/(kgK)
rho = 1.2; %kg/m^3
%Cabin Area and Volume Values
L = 5; %m
W = 6; %m
H1 = 3; %m
H2 = 3; %m
A1 = 2*H1*W + 2*L*H1; %m^2
A2 = W*L; %m^2
A3 = 2*L*(3/sind(45)); %m^2 Only roof, neglect walls of second floor
V1 = L*W*H1; %m^3
V2 = .5*W*L*H2; %m^3
%Time and Temp arrays
Lt = 2*86400; %s
h = 1.5; %Step size, I think 1 second is fair
N = Lt/h; %
%Preallocate arrays
T1 = zeros(1,N); %Floor 1
T2 = zeros(1,N); %Floor 2
Q1 = zeros(1,N);
Q2 = zeros(1,N);
Q3 = zeros(1,N);
t = zeros(1,N); %Time domain
Tout = -10*sin(2*pi*t/86400); %C
%Initial conditions
t(1) = 0;
T1(1) = 5; %C
T2(1) = 7; %C
% %Q Equations
Q1 = k1*(T1-Tout);
Q2 = k2*(T1-T2+5);
Q3 = k3*(T2-Tout);
%Qin = linspace(0,2500,N); %W/(m^2K)
Qin = 1500; %W/(m^2K)
fTemp1 = @(t,T1) (Qin*Ain-Q1*A1-Q2*A2)/(Cair*V1*rho)
% Differential Equations
for i = 1:N-1
t(i+1) = t(i) + h;
T1(i+1) = T1(i+1)+h*fTemp1(t(i),T1(i));
end
  1 Comment
Rik
Rik on 4 Apr 2021
I recovered the removed content from the Google cache (something which anyone can do). Editing away your question is very rude. Someone spent time reading your question, understanding your issue, figuring out the solution, and writing an answer. Now you repay that kindness by ensuring that the next person with a similar question can't benefit from this answer.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 2 Apr 2021
T1 = zeros(1,N); %Floor 1
array
Q1 = k1*(T1-Tout);
array because T1 is array
fTemp1 = @(t,T1) (Qin*Ain-Q1*A1-Q2*A2)/(Cair*V1*rho)
Uses the array Q1 and therefore computes an array
T1(i+1) = T1(i+1)+h*fTemp1(t(i),T1(i));
You are trying to store the array of results in a scalar
t = zeros(1,N); %Time domain
Tout = -10*sin(2*pi*t/86400); %C
t is all 0 so that is sin(0). What is the point of that?
  3 Comments

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!