Error in ode15s
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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)
0 个评论
更多回答(1 个)
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);
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!