Good Evening dear Matlab Community,
Now that my first part of code works, I have the ambition to make it a little complicated but I can't figure out how to implement my plan in matlab:
in the code below you can see that I'm solving a system of two differential equations. Now my challenge is that I would like to solve it with different conditions on certain parameters over the full interval l. I would like to divide the full interval l into sections i each itself divided into two zones, j.
Each section i starts with a conductive zone (j=1) of say l=3 meter for which:
Aap=lcontAcp=Aaphap=17kap=0.018
And ends with a convection zone (j=2) of l=2 meter for which following is true:
Aap=2*lcontAcp=0hap=20kap=0.02
After this, comes the conductive zone of the next section…
I am confused about how to define indices for the sections and zones and whether I need to include loops within the functions corresponding to my ODE in order to solve my system. I have tried (and failed) by introducing following lines within the script of my ODE functions:
for j=1 Aap=lcontAcp=Aaphap=17kap=0.018endfor j=2Aap=2*lcontAcp=0hap=20kap=0.02end
If I define the array J=[1 2], how can I make sure that the same indice is used to solve both ODE for each section?
Ideally I would even like to be able to build-in variation for the parameters of the conductive zone between two different sections (like for section 1 and j=1, hap=17 and for section 2 and j=1, hap=5) but I guess once I understand how to implement it for one case, I'll be able to extend it to further! 🙂
[l,y]=ode45(@myODE,[0 45],[0.48,30]);plot(l,y(:,:))function dy = myODE(l,y)global uu=y(1);global TpTp=y(2);dTpdl = myODE1(l,u,Tp);dudl = myODE2(l,u,Tp);dy = [dudl;dTpdl];endfunction dudl = myODE2(l,u,Tp)lcont=2.855; Psatp = 0.13*exp(18-3800/(Tp+227.03));Phi= 1-exp(-(47*u^2+0.1*Tp*u^1.06));Ppw= Psatp*Phi;dudl=-(kap*Aap)*(Ppw/(Tp+273.15)-0.19);endfunction dTpdl=myODE1(l,u,Tp)lcont=2.855; hcp0=0.65; Psatp = 0.13*exp(18-3800/(Tp+227.03));Phi= 1-exp(-(47*u^2+0.1*Tp*u^1.06));Ppw= Psatp*Phi;DHs = 0.1*(u^1.1)*((Tp+275.15)^2)*(1-Phi)/Phi;DHvap = 1000*(2501-2.3*Tp);DHevap = DHs+DHvap;dTpdl=((hcp0+0.955*u)*(140-Tp)*Acp+hap*(100-Tp)*Aap+DHevap*(-kap*Aap)*(Ppw/(Tp+273)-0.19))/(1.4+4.18*u); end
Best Answer