Error in ode15s
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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);
%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
Réponse acceptée
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)
0 commentaires
Plus de réponses (1)
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);
0 commentaires
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!