Code for a stochastic simulation

3 visualizzazioni (ultimi 30 giorni)
Stefan
Stefan il 26 Nov 2014
Commentato: Roger Stafford il 26 Nov 2014
Hi everyone, I'm doing a homework problem for one of my classes, and the professor gave us a template with most of the code already written. However, he has not actually explained how to do the parts we have to fill in, because he likes to talk about personal stories instead of actually teaching. I was wondering if you users could help me out. The first part we have to fill in uses time series, and I have no clue how they work. Here is the problem and code: 1. Write your stochastics simulation to simulate this reaction. Parameters: k1=4;k2=10,k3=1,k4=20,k5=1,k6=20,k7=2; Initial conditions: A=10,B=10,C=10; Simulate the reactions until about 200 time units. Plot abundances of A and C vs. time in blue and red.
function out = main() close all;
pars=[4 10 1 20 1 20];
k1=pars(1); k2=pars(2); k3=pars(3); k4=pars(4); k5=pars(5); k6=pars(6);
init=[10 10 10];
steps = 500000;
ts= zeros(steps+1,4);
ts(1,2:4) = init;
a=ts(1,2); b=ts(1,3); c=ts(1,4);
for i = 2:(steps+1)
lmd1 = k1*a*b;
lmd2 = c*k2;
lmd3 = a*k3;
lmd4 = k4;
lmd5 = b*k5;
lmd6 = k6;
rate = [lmd1 lmd2 lmd3 lmd4 lmd5 lmd6];
lmd = sum(rate);
p= cumsum(rate)/lmd;
U = rand(1,2);
tstep = %fill in here
ts(i,1) =%fill in here
Any help at all would be wonderful! Thank you very much!
  1 Commento
Roger Stafford
Roger Stafford il 26 Nov 2014
Stefan, you are not likely to get much help for your request until you give a reasonably detailed description of the stochastic process you are simulating. It is presumably some kind of chemical reaction, but giving details about it is important. Moreover, you should show some matlab code that you have written so that comment can be made on the code rather than expecting contributors to furnish the entire answer to you.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Mathematics and Optimization in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by