Error in ode15s

5 vues (au cours des 30 derniers jours)
N G
N G le 9 Juil 2024
Modifié(e) : Torsten le 9 Juil 2024
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 commentaire
Torsten
Torsten le 9 Juil 2024
Modifié(e) : Torsten le 9 Juil 2024
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 ?

Connectez-vous pour commenter.

Réponse acceptée

Sam Chak
Sam Chak le 9 Juil 2024
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)

Plus de réponses (1)

Walter Roberson
Walter Roberson le 9 Juil 2024
[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);

Tags

Produits


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by