Error in ode15s

1 次查看(过去 30 天)
N G
N G 2024-7-9
编辑: Torsten 2024-7-9
I'm trying to run a code but its showing an error for ode15s, where am I going wrong?
kfin=0.8;
hfin=7e-4;
Rin=3;
Rout=9;
b=1;
Ta=400;
Tu=30;
T0=35;
Nr=51;
rhofin=0.8;
cpfin=0.5;
%Step and Increment
r=linspace(Rin,Rout,Nr);
dr=r(2)-r(1); %delta-R
t=linspace(0,10,100); %time till 10 sec
%simplify calc
m=rhofin*cpfin/kfin;
n=2*hfin./kfin./b;
o=2*dr*hfin./kfin;
%Initial condition
IC=T0.*ones(Nr,1);
%Solver ODE15s
[t,T]=ode15s(@f,t,IC);
Not enough input arguments.

Error in solution>f (line 36)
dTdt=zeros(Nr,1);

Error in odearguments (line 92)
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.

Error in ode15s (line 148)
odearguments(odeIsFuncHandle, odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
%recalculation
T(:,1)=Ts+30.*t-6.*t.^2; %BC-1
T(:,end)=(o.*Tu+4*T(:,end-1)-T(:,end-2))./(3+o); %BC-2
imagesc(r,t,T)
colormap jet
colorbar
grid on
title('Temp Profile')
xlabel('Radius')
ylabel('Time in sec')
%function
function dTdt=f(t,T,Rin,Rout,b,Ts,Tu,T0,Nr,m,n,o,dr,r)
dTdt=zeros(Nr,1);
T(1)=Ts+30.*t-6.*t.^2; %BC-1
T(end)=(o.*Tu+4*T(end-1)-T(end-2))./(3+o); %BC-2
%Interior
for i=2:Nr-1
d2Tdr2(i)=(T(i+1)-2*T(i)+T(i-1))./dr.^2;
dTdr(i)=(T(i+1)-T(i-1))./(2.*dr);
dTdr(i)=(d2Tdr2(i)+(1./r(i)).*dTdr(i)-n.*(T(i)-Tu))./m;
end
end
  1 个评论
Torsten
Torsten 2024-7-9
编辑:Torsten 2024-7-9
Note that you always return dTdt = zeros(Nr,1) in your function f. Thus the solution will always remain at its initial state.
You know that you can use "pdepe" to solve this problem ?

请先登录,再进行评论。

采纳的回答

Sam Chak
Sam Chak 2024-7-9
I suspect there is also a typo for Ta because the 'a' key is next to the 's' key.
If you follow the advice in Walter's Answer, you should get this figure.
Ts = 400; % originally Ta
[t, T] = ode15s(@(t, T) f(t, T, Rin, Rout, b, Ts, Tu, T0, Nr, m, n, o, dr, r), t, IC);
imagesc(r,t,T)

更多回答(1 个)

Walter Roberson
Walter Roberson 2024-7-9
[t,T]=ode15s(@f,t,IC);
ode15s is to invoke function f, passing it time in the first parameter and passing initial conditions in the second parameter.
function dTdt=f(t,T,Rin,Rout,b,Ts,Tu,T0,Nr,m,n,o,dr,r)
but f needs lots of different parameters, that are not going to be provided by ode15s.
You need
[t,T]=ode15s(@(t,T)f(t,T,Rin,Rout,b,Ts,Tu,T0,Nr,m,n,o,dr,r), t, IC);

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

标签

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by