Hello,
I have a system that I want to solve numerically (attached is the pde-ode file). I know a little about how to solve ode and pde separately, but I don't know how to combine ode and pde parts in MATLAB.
Here is my code: (I am sorry for my rough code)
T=120;c10 = 1.3;c20 = 0.03;g10 = 0.07;g20 = 1.37;[t, state_variable]=ode45(@LV,[0 T],[c10,c20,g10,g20]);c1 = state_variable(:,1);c2 = state_variable(:,2);g1 = state_variable(:,3);g2 = state_variable(:,4);%[c1,t]
x = linspace(0,L,20);%t = [linspace(0,0.05,20), linspace(0.5,5,10)];
m = 0;sol = pdepe(m,@heatpde,@heatic,@heatbc,x,t);hold onplot(t,c1,'LineWidth',2)plot(t,c2,'LineWidth',2)% Various commands to make graph clearer
h=legend('c1','c2','g1','g2');xlabel('Time','Fontsize',16)ylabel('concentration','Fontsize',16)set(gca,'XTick')set(h,'Fontsize',20)function f=LV(t,state_variable)c1=state_variable(1);c2=state_variable(2);g1=state_variable(3);g2=state_variable(4);%here i deleted many parameters
% Equations
dc1 =(k0+kcat*c1^n)*g1*C(0,t)-kbar*c1;dc2 =(k0+kcat*c2^n)*g2*C(L,t)-kbar*c2;dg1=kon/(1+K*c1^m)*G(0,t)-koff*g1;dg2=kon/(1+K*c2^m)*G(L,t)-koff*g2;%f=[dx;dy;];
f=[dc1;dc2;dg1;dg2;];endfunction [c,f,s] = heatpde(x,t,C,dCdx)c = 1/Dc;f = dCdx;s = 0;endfunction C0 = heatic(x)C0 = 0.17;endfunction [pl,ql,pr,qr] = heatbc(xl,Cl,xr,Cr,t)pl = -Dc*Cl+dc1;ql = 0;pr = -Dc*Cr-dc2;qr = 0;end
Thank you very much!
Best,
Ziyi
Best Answer