Error in ODE45

조회 수: 2 (최근 30일)
Ajmal R S
Ajmal R S 2020년 10월 7일
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

채택된 답변

madhan ravi
madhan ravi 2020년 10월 7일
편집: madhan ravi 2020년 10월 7일
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
Ajmal R S
Ajmal R S 2020년 10월 7일
Yes, I forgot to include that, but the mistake was in the multiplication. Thank you

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

GRK
GRK 2020년 10월 7일
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
Ajmal R S
Ajmal R S 2020년 10월 7일
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
SIDDABOENA Laxmi Venkata Sai 2022년 4월 4일
share your matlab code AJMAL RS

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by