## Thursday, May 23, 2013

### Modeling & Simulation of Chemical Reaction | Continuous System Simulation | C++ Implementation

Chemical reactions exhibit dynamic equilibrium, which means that a combination reaction is also accomplished by the reverse process of decomposition reaction. At the steady state the rates of the forward and the backward reaction is same.

In addition to the forward reaction where Ch1 and Ch2 react to produce Ch3, there may also be backward reaction, where by, Ch3 decomposes back into Ch1 and Ch2. Let the rate of formation of Ch3 be proportional to the product of the amounts Ch1 and Ch2 present in the mixture and let the rate of decomposition of Ch3 be proportional to its amount in the mixture.
Let us consider C1, C2  and C3 Amount of Ch1, Ch2 and Ch3 at any instant of time t, the rate of increase of C1, C2& C3 are given by the following differential equations:

dC1/dt = K1C3– K1C1C2
dC2/dt = K2C3– K1C1C2
dC3/dt=2K1C1C2-2K2C3

Where K1and K2 are constants.

As soon as the chemicals Ch1 and Ch2are mixed, the reaction starts and the amount of C1, C2, C3 in the mixture goes on changing as time progresses.The simulation of reaction will determine the state of the system. i.e. value of quantities C1, C2 and C3at different points in time. Starting at zero time, a very small increment of time is taken in each step. It is assumed to be so small, that all changes in the mixture can be taken to occur at theend of each increment. If C1(t), C2(t) and C3(t) are the quantities to there chemicals at time t, then at time t +  Δt, the quantities are ;
C1(t +  Δt) = C1(t) + dC1(t)/dt
C2(t +  Δt) = C2(t) + dC2(t)/dt
C3(t + Δt) = C3(t) + dC3(t)/d

After forming the the mathematical model, we can simulate the system using following program written in C++:
// Simulate Chemical Reaction,  +Jivan Nepali
#include<iostream>
#include<fstream>
using namespace std;
float k1 = 0.008,k2 = 0.002,del_t = 0.1;
float calc_c1(float c1, float c2, float c3)
{
return (c1+(k2*c3-k1*c1*c2)*del_t);
}
float calc_c2(float c1, float c2, float c3)
{
return (c2+(k2*c3-k1*c1*c2)*del_t);
}
float calc_c3(float c1, float c2, float c3)
{
return (c3+(2*k1*c1*c2-2*k2*c3)*del_t);
}
int main()
{
float c1 = 25,c2 = 80, c3 =0;
int i;
float temp_c1,temp_c2,temp_c3;
ofstream outfile("simulation_lab.txt");
outfile<<c1<<","<<c2<<","<<c3<<"\n";
for(i=1;i<400;i++)
{
temp_c1 = calc_c1(c1,c2,c3);
temp_c2 = calc_c2(c1,c2,c3);
temp_c3 = calc_c3(c1,c2,c3);
c1 = temp_c1;
c2 = temp_c2;
c3 = temp_c3;
outfile<<c1<<","<<c2<<","<<c3<<"\n";
}
outfile.close();
cout<<"\nAll data printed on the file \"Simulation_Lab.txt\" on your project folder.\n";
cout<<"\nHave a look!!!\n\n";
return 0;
}
To simulate the result obtained through the above model, we can use following MATLAB code:

%Simulate Chemical Reaction, +Jivan Nepali
plot(data(:,1),'b-');
hold on;
plot(data(:,2),'r-');
hold on;
plot(data(:,3),'k-');
legend('reactant c1','reactant c2','product c3');

The graph obtained using the MATLAB will be as shown:

Enjoy Simulating....!!!

1. Be that as it may, there were a few providers who were assaulted by the DEA; the first to be struck was JLF Primary Materials.Research chemicals

2. While taking care of and capacity of chemicals ought to be finished with mind, the recognition of precautionary measures when blending distinctive substances is significantly all the more convincing. https://topas.com

3. Extremely pleasant article, I appreciated perusing your post, exceptionally decent share, I need to twit this to my adherents. Much appreciated!.  Contact us

5. Spot on with this write-up, I must say i believe this excellent website needs much more consideration. I’ll probably be once again to learn a great deal more, many thanks that information buy am-2201 powder online

6. Thanks For sharing this Superb article.I use this Article to show my assignment in college.it is useful For me Great Work. mephedrone for sale uk

7. About. We are one of the leading pharmacies which offer high-quality products at minimal prices. Explore our category of products today by visiting our website buy rivotril online

8. Buying medicine over the Internet can make life a lot easier. Medicines on the Internet are sometimes cheaper. Your pills are delivered to your door.
buy pain medication online without prescription
buy pain relief online without prescription

9. RS DYNAMICS supports security across many markets - national and homeland security, critical infrastructure, event management, medtech and ecological tasks.
explosive trace detector parts
trace explosive detector
Trace Detection
Faster security screening
security screening

10. Its my great pleasure to visit your blog and to enjoy your great posts here. I like it a lot. I can feel that you paid much attention for those articles, as all of them make sense and are very useful.  préstamos privados

11. Stickers2go is the UK’s no 1 manufacturer of custom stickers printing and printed labels Order custom stickers and labels, in ANY shape and size, powered sticker printing for industry-leading quality. Order now to get discount on bespoke stickers printing

12. Stickers2go is the UK’s no 1 manufacturer of custom stickers printing and printed labels Order custom stickers and labels, in ANY shape and size, powered sticker printing for industry-leading quality.Order now to get discount on bespoke stickers printing

13. The Packaging papa are as extraordinary as they are unique and work wonders for businesses Packaging PAPA is aiming at creating boxes from extremely biodegradable material. They taking small stores to local domination, to national level brands to multi-national organization.

14. Quality Packaging Solutions, the name itself is self-evident of our quick and efficient services. We at Quality Packaging Solutions offer a wide variety of customized packaging options to our customers. You can get your custom cigar boxes at Quality Packaging Solutions in a cost-effective manner. We specialize in retail as well as wholesale Custom Packag

15. You can get your Custom Cannabis Boxes at Quality Packaging Solutions in a cost-effective manner.Qualitypackagingsolutions.co.uk offers FREE shipping around the globe. Our standard turnaround is 10-12 Business Days with FREE shipping. We also offer Rush Services with 6-8 Business Days plan where up to 25% expedite may be applicable.

16. The custom boxes are as extraordinary as they are unique and work wonders for businesses Packaging boxes is aiming at creating boxes from extremely biodegradable material.micro electronic blue print box They're taking small stores to local domination, to national level brands to multi-national organization.Marijuana soap boxes

17. Custom boxes is the U.S manufacturer of and printed labels Order custom boxes and labels, in ANY shape and size, powered printing for industry-leading quality. Custom Packaging Boxes With Logo Plus there's free delivery after you order, and our guarantee to beat any like-for-like quote for printed boxes and labels.

18. Individuals who are influenced by MCS as a rule have encountered harmful measures of substances through rehashed openness to engineered chemicals. tadalafil powder

19. This comment has been removed by the author.

20. This comment has been removed by the author.

21. our Post is very informative. If you are looking for the new CBD Sample Boxes then you must get to our company site Custom Boxes Printing and check out new box styles to pack your products in them.

22. Your article is very beneficial for us.If you are looking for new boxes like vape subscription box then you can visit our websiteQuality Packaging Solution .Our boxes have good quality and you can order our boxes for packing your products.

23. Your subject is very helpful for us.If you are looking for great quality boxes like rectangle gift boxes with Lids. you can visit our website for your Custom Boxes Printing. Our boxes have their name in the world. You can order them for packing your beautiful products.

24. Every business has Packaging needs, and we are specialists in knowing your custom boxes printing needs. We produce Custom Printing Services, Custom Boxes and additionally carefully make them fill your company a twofold need of Custom Printing Services co. UK and furthermore developing your things.custom packaging uk custom packaging uk

25. Thank you for helping out, wonderful info. “A man will fight harder for his interests than for his rights.”custom boxes custom boxes

26. bespoke packaging boxes At Bespoke Packaging UK we strongly believe in the interests of bespoke packaging, which has multiple benefits. Over the last few decades, we have built up vast experience in producing bespoke packaging for a vast range of items.

27. bespoke packaging boxes At Bespoke Packaging UK we strongly believe in the interests of bespoke packaging, which has multiple benefits.

28. I was reading your article and wondered if you had considered creating an ebook on this subject. Your writing would sell it fast. You have a lot of writing talent. Research Chemicals