Info

This question is closed. Reopen it to edit or answer.

How to enter a matrix into this and run a loop to capture the answers to plot them

1 view (last 30 days)
I want to put a matrix in for the k1-k3 and the c1-c3 but cannot find anywhere how to do this to capture the answer becasue the answer is complicated
k1=1; %mol/m3
k2=50; %1/s
k3=25; %1/s
par=[k1 k2 k3];
options=odeset('maxstep',0.01,'abstol',1e-16,'reltol',1e-4);
[t c]=ode45(@combustion, [0:0.0001:1],[100 1 0],options,par);
figure(1)
plot(t,c(:,1),'b','LineWidth',1.5)
hold on;
plot(t,c(:,2),'r','LineWidth',1.5)
hold on;
plot(t,c(:,3),'g','LineWidth',1.5)
hold off;
xlabel('Time/s')
ylabel('Concentration')
legend ('A','B*','D*')
%%%%%%%This will be run through the function below
function dcdt= combustion(t,c,par)
%The values of rate coefficients are as follows:
k1=par(1); k2=par(2); k3=par(3);
dcdt(1,1)=-k1*c(1,1)*c(2,1);
dcdt(2,1)=(2*k2*c(3,1))-(k1*c(1,1)*c(2,1))-(k3*c(2,1));
dcdt(3,1)=(k1*c(1,1)*c(2,1))-(k2*c(3,1));

Answers (0)

Community Treasure Hunt

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

Start Hunting!