I try to optimalize a temperature when looking at different concentrations for a chemical reaction. I get a good plot for values of k from 1 tot 70 but when going higher it won't work anymore. I don't know what to do, anyone?

clc
clear all
tstep=0.01;
tend=10;
Temp=[];
temp_step=1;%telkens een graadje warmer
R=8.314;% gasconstante
t(1)=0; % we beginnen op tijdstip nul
doelfunctievector=[];
T=270;
i=1;
for k=1:100
T=T+temp_step; %telkens je in de loop gaat wil je rekenen voor een andere temperatuur
k1=5.9E8*exp(-50E3/(T*R)); % Arhenius dus k ifv T
k2=2.4E4*exp(-25E3/(R*T));
k3=3.4E17*exp(-100E3/(R*T));
constantes=[-k1 0 0 0;k1 -k2 0 0;0 k2 -k3 0;0 0 k3 0];
concentratie=[1; 0; 0; 0]; %kolommatrix
resultaat=concentratie;
for i=1:(tend/tstep)
concentratie=concentratie+(tstep*constantes*concentratie);
resultaat=[resultaat concentratie]; %er komt een tweede kolom bij dus 4x2 matrix
t(i+1)=t(i)+tstep;
end
resultaat=resultaat.'; %transponeren van de matrix
C3=resultaat(:,3); %neem de derde kolom
[C3_max,i]=max(C3);
doelfunctie=C3_max/(t(i));%c3max
volgende_temp=T;
Temp= [Temp volgende_temp];
doelfunctievector=[doelfunctievector doelfunctie];
end
plot(Temp,doelfunctievector)
%doelfunctievector

Answers (1)

You should reset t(1) to zero before the inner loop. You might not even need a vector t. Just use t = t + tstep, as you only use the last element of t in the remainder of your code.
This code could also be made much faster by using pre-allocation.
btw, your comments are in Dutch, which only a minority is able to begrijp ...

Categories

Find more on Chemistry in Help Center and File Exchange

Tags

Asked:

on 30 Mar 2018

Edited:

on 30 Mar 2018

Community Treasure Hunt

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

Start Hunting!