Error in ODE45
Show older comments
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
Accepted Answer
More Answers (1)
GRK
on 7 Oct 2020
1 vote
There are two errors in this code. first one is that there is no variable name called Fr.
Second one is F1 shoulde be multipliead it means you have to use multiply symbole (*) when you want to multiply some thing.
as per my assumption F1 = Fr i think. Just Replace the below Formula with the original formula and Run the program.
dT1 = (F1*(Tc-T1)+F1*(T2-T1)+(Q1/rho_w*Cp))/(A2*h2);

2 Comments
Ajmal R S
on 7 Oct 2020
SIDDABOENA Laxmi Venkata Sai
on 4 Apr 2022
share your matlab code AJMAL RS
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!