2 views (last 30 days)

For my study I recieved an assignment to calculate the most optimal way of isolating a house. This is done using matlab.

The assignment is included underneath.

Me and my group are getting several errors, and really dont know what is going wrong.

We would really appreciate it if someone could help us out.

The script

% define constants

A = 1;

B = 2;

Cint = 1.0*10^4;

Cwall = 5.0*10^2;

R1 = 0.1;

R2 = 0.08;

Rwin = 0.1;

Tamb = dlmread('Temperaturesummer30.dat');

QHVAC = 0;

% time dependent window

tspan = [0:1:1440]; % calculate from t=0 up to t=1440

% can define the time interval steps

y0 = [18 20]; % initial conditions

Twall = y0(1);

Tint = y0(2);

% define your ode-function

odefunc = @(t,dydt) odeFunction(t, Twall, Tint, Tamb, Cwall, Cint, R1, R2, Rwin, QHVAC);

% integrate the system of differential equations from tspan(1) to

% tspan(2) with initial conditions y0

[t,dydt] = ode45(odefunc, tspan, y0);

% plot the results

plot(t,dydt)

The function

function [dydt] = odeFunction(t, Twall, Tint, Tamb, Cwall, Cint, R1, R2, Rwin, QHVAC)

% set of ordinary differential equations

% input: A - constant

% B - constant

% t - the time variable

% y - the state variable

%output: dydt - the set of equations

% initialize the set of equations

dydt = zeros(2,1);

% define the set of equations

dydt(1) = ((Tamb-Twall)/(Cwall *R2)) + ((Tint-Twall)/(Cwall*R1)) %Twall %y(2)+A;

dydt(2) = ((Twall-Tint))/(Cint *R1) + ((Tamb-Tint)/(Cint* Rwin)) + (QHVAC/Cint) %Tint %(A/B)*y(1);

end

The errors

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

Error in odeFunction (line 15)

dydt(1) = ((Tamb-Twall)/(Cwall *R2)) + ((Tint-Twall)/(Cwall*R1)) %Twall %y(2)+A;

Error in odeScript>@(t,dydt)odeFunction(t,Twall,Tint,Tamb,Cwall,Cint,R1,R2,Rwin,QHVAC) (line 26)

odefunc = @(t,dydt) odeFunction(t, Twall, Tint, Tamb, Cwall, Cint, R1, R2, Rwin, QHVAC);

Error in odearguments (line 90)

f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.

Error in ode45 (line 115)

odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);

Error in odeScript (line 31)

[t,dydt] = ode45(odefunc, tspan, y0);

>>

Star Strider
on 22 Oct 2020

I cannot run your code, since I do not have the ‘Tamb’ data.

Nevertheless ‘Tamb’ is likely the problem, since it appears to be an array of some sort, and that is throwing the error. If it is time-dependent, it will be necessary to interpolate it using the approach in ODE with Time-Dependent Terms in the ode45 (and related functions) documentation.

Star Strider
on 22 Oct 2020

I get this plot:

It is not exactly the one in the assignment, however you will need to sort that, since it most likely depends on where the 2 values of ‘Twall’ belong, since I am not certain where ‘Twall(1)’ and ‘Twall(2)’ go in the derivatives. I assigned them as I did simply to get the code to run without throwing errors.

The ‘odeFunction’ file did not change from my previous Comment. The calls to it and the plot call are:

% define your ode-function

odefunc = @(t,Twall) odeFunction(t, Twall, Tint, Tamb, Cwall, Cint, R1, R2, Rwin, QHVAC);

% integrate the system of differential equations from tspan(1) to

% tspan(2) with initial conditions y0

[t,y] = ode45(odefunc, tspan, y0);

% plot the results

figure

plot(t,y)

grid

xlabel('time (in minutes)')

ylabel('Temperature (celsius)')

as previously (with only the axis titles added).

Opportunities for recent engineering grads.

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

Start Hunting!
## 5 Comments

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/622608-ode-45-and-function-combination#comment_1078623

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/622608-ode-45-and-function-combination#comment_1078623

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/622608-ode-45-and-function-combination#comment_1078633

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/622608-ode-45-and-function-combination#comment_1078633

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/622608-ode-45-and-function-combination#comment_1078638

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/622608-ode-45-and-function-combination#comment_1078638

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/622608-ode-45-and-function-combination#comment_1078918

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/622608-ode-45-and-function-combination#comment_1078918

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/622608-ode-45-and-function-combination#comment_1078983

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/622608-ode-45-and-function-combination#comment_1078983

Sign in to comment.