Error in ODE45

4 views (last 30 days)
Ajmal R S
Ajmal R S on 7 Oct 2020
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

madhan ravi
madhan ravi on 7 Oct 2020
Edited: madhan ravi on 7 Oct 2020
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.
  1 Comment
Ajmal R S
Ajmal R S on 7 Oct 2020
Yes, I forgot to include that, but the mistake was in the multiplication. Thank you

Sign in to comment.

More Answers (1)

GRK
GRK on 7 Oct 2020
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
Ajmal R S on 7 Oct 2020
No, I am sorry. It was my mistake. I forgot to add the Fr function, I added it and got the answer. Thank you for your help
SIDDABOENA Laxmi Venkata Sai
share your matlab code AJMAL RS

Sign in to comment.

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!