MATLAB: Error in ODE45

MATLABmodelodeode45

Guys I tried to code a Stirred Tank Heater System using MATLAB, I modelled the equation and all
clc;
clear all;
T1_0 = 325.4;
tspan = [0 10];
[tsol,T1sol] = ode45(@(t,T1) heat(t,T1), tspan, T1_0);
plot(tsol,T1sol)
grid on
xlabel('t')
ylabel('T1')
title('Solutions of Heat Balance on Tank-1')
And this is the ode function "heat" that I have used
function dT1 = heat(t,T1)
% Inputs
A2 = 7.854e-05; %Cross-Sectional Area Tank 2
Tc = 303; %Cooling Water Temp
T2 = 320.1; %Tank 2 Temp
h2 = 0.41; %Level h2
rho_w = 1000; %Density in kg/m3
Cp = 4182; %Cp value in J/KgK
u1 = 0.45; %Flow F1
F1_A = 8.0368e-11;
F1_B = 456.85e-11;
F1_C = 42379e-11;
F1 = F1_A*(u1^3)-F1_B*(u1^2)+F1_C*(u1);
u4 = 0.45; %Heat Input Q1
Q1_A = 7.9798;
Q1_B = 0.9893;
Q1_C = 0.0073;
Q1 = Q1_A*(u4)+Q1_B*(u4^2)-Q1_C*(u4^3);
dT1 = (F1(Tc-T1)+Fr(T2-T1)+(Q1/rho_w*Cp))/(A2*h2);
end
But I am getting the following errors when I run the code.
Array indices must be positive integers or logical values.
Error in heat (line 29)
dT1 = (F1(Tc-T1)+Fr(T2-T1)+(Q1/rho_w*Cp))/(A2*h2);
Error in CACE>@(t,T1)heat(t,T1) (line 7)
[tsol,T1sol] = ode45(@(t,T1) heat(t,T1), tspan, T1_0);
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 CACE (line 7)
[tsol,T1sol] = ode45(@(t,T1) heat(t,T1), tspan, T1_0);
Please, any help would be nice

Best Answer

MATLAB doesn't have implicit multiplication, hence:
dT1 = (F1*(Tc-T1)+Fr*(T2-T1)+(Q1/rho_w*Cp))/(A2*h2);
Note: Fr is not defined in your code.