This is the web version of EJS interface
EJS version 4.3.2
  1. Title=Three State Nuclear Decay
  2. Author=Wolfgang Christian - Davidson College, remix by lookang
  3. Abstract=wochristian@davidson.edu
  4. CaptureTools=false
  5. DataTools=false
  6. LanguageTools=false
  7. EmersionSupport=false
  8. UseInterpreter=true
  9. AuxiliaryFiles=./ThreeStateNuclearDecay/;
    NameValueTypeDimension
    NameValueTypeDimension
    NameValueTypeDimension
    NameValueTypeDimension

    Initialize Particles

    if(plotMode==0) _view.bothRadioButton.setSelected(true); t=0; n1=1; n2=0; n3=0; _resetSolvers(); org.opensourcephysics.numerics.EJSODE ode= _getODE("ODE Evolution"); ode.step(); p1=1-Math.exp(-k1*dt); p2=1-Math.exp(-k2*dt); p12=n2; p13=n3; //_println("topDecay="+p1+" p12+p13="+(p12+p13)); //_println("n1="+n1+" n2="+n2+" n3="+n3+" total="+(n1+n2+n3)); checkParticleNumber(); setParticlePosition(); t=0; n1=N1=N10; n2=N2=N20; n3=N3=0; _view.resetTraces(); dN1=Double.NaN; dN2=Double.NaN; _resetSolvers();
    Indep. Var. Increment
    d n1 /dt=-k1*n1
    d n2 /dt=+k1*n1-k2*n2
    d n3 /dt=k2*n2
    SolverRungeKuttaFehlberg AbsoluteTolerance=tol

    FixRel Page

    t121 = Math.log(2)/k1; t122 = Math.log(2)/k2; tint = t/t121; for (int n=0; n<=tint /* Iterations */ ; n++) { n1x[n] = t121*(n+1); t121x[n] = t121*(n+1); n1s[n]=N10/(Math.pow(2.0,n+1)); }
    public void checkParticleNumber(){ N=N10+N20; if(N==x.length) return; x=new double[N]; y=new double[N]; colors=new java.awt.Color[N]; }
    public void setParticlePosition() { double radius=particleDiameter/2; double sampleWidth=sampleSize-particleDiameter; for(int i=0; i<N10; i++){ x[i]=radius+sampleWidth*Math.random(); y[i]=radius+sampleWidth*Math.random(); colors[i]=java.awt.Color.RED; } for(int i=N10; i<N; i++){ x[i]=radius+sampleWidth*Math.random(); y[i]=radius+sampleWidth*Math.random(); colors[i]=java.awt.Color.GREEN; } if(N10==0 || N20==0) return; for(int i=0; i<4*N; i++){// randomize color order int r1=(int)(N*Math.random()); int r2=(int)(N*Math.random()); Color c=colors[r1]; colors[r1]=colors[r2]; colors[r2]=c; } }
    public void computeStochasticDecay () { double topToMiddleProbability=1-Math.exp(-k1*dt); // 1->2 decay probability within dt //double topToBottomProbability=1-Math.exp(-(k1+k2)*dt); // 1->3 decay probability within dt double middleToBottomProbability=1-Math.exp(-k2*dt); // 2->3 decay probability within dt dN1=0; dN2=0; for (int i = 0; i < N; i++) { double p=Math.random(); if(colors[i].equals(java.awt.Color.RED)&& p<p12) { // decay from state 1 to 2 colors[i]=java.awt.Color.GREEN; N1--; N2++; dN1++; } else if(colors[i].equals(java.awt.Color.RED)&& p<p12+p13) { // decvay from state 1 to 3 colors[i]=java.awt.Color.BLUE; N1--; N3++; dN1++; dN2++; } else if(colors[i].equals(java.awt.Color.GREEN)&&p<p2) { // decay from state 2 colors[i]=java.awt.Color.BLUE; N2--; N3++; dN2++; } } }
    EJSVIEW: Click link to view it's content
    Control variables:(testing)
    title="Three-State Radioactive Decay"
    layout=border
    visible=true
    location="123,172"
    size="619,474"
    position=south
    layout=VBOX
    layout=HBOX
    borderType=LOWERED_ETCHED
    layout=BORDER:0,0
    position=west
    text=" N1 = "
    alignment=RIGHT
    background=RED
    position=center
    variable=N1
    format="0"
    editable=t==0
    action=N1=Math.max(1,N1); N1=Math.min(10000,N1); N10=N1; _initialize();
    columns=4
    size="40,24"
    tooltip="parent nuclides-Upper state particle number."
    layout=HBOX
    border=1,1,1,1
    borderType=MATTE
    borderColor=RED
    position=west
    text=" t1_1/2 = "
    alignment=RIGHT
    tooltip="half life the time taken for the activity of a given amount of a radioactive substance to decay to half of its initial value"
    position=center
    variable=t121
    format="0.000#"
    editable=t==0
    action=//t121=Math.min(k1,1000); //k1=Math.max(k1,0); //t121 = Math.log(2)/k1; k1 = Math.log(2)/t121; _initialize();
    columns=4
    size="40,24"
    tooltip="half life — symbol t1/2 — the time taken for the activity of a given amount of a radioactive substance to decay to half of its initial value"
    position=north
    text="s"
    tooltip="second"
    layout=BORDER:0,0
    position=west
    text=" $\\lambda$1 = "
    alignment=RIGHT
    tooltip="$\\lambda$1=k1 decay constant"
    position=center
    variable=k1
    format="0.000#"
    editable=t==0
    action=k1=Math.min(k1,1000); k1=Math.max(k1,0); _initialize();
    columns=4
    size="40,24"
    tooltip="dN1/dt= - k1*N1 Level 1 decay rate=decay constant $\\lambda$."
    layout=BORDER:0,0
    position=west
    text=" N2 = "
    alignment=RIGHT
    background=0,128,0,255
    foreground=WHITE
    position=center
    variable=N2
    format="0"
    editable=t==0
    action=N2=Math.max(1,N2); N2=Math.min(10000,N2); N20=N2; _initialize();
    columns=4
    size="40,24"
    tooltip="Middle state particle number."
    layout=HBOX
    border=1,1,1,1
    borderType=MATTE
    borderColor=0,128,0,255
    position=west
    text=" t2_1/2 = "
    alignment=RIGHT
    tooltip="middle stage half life- the time taken for the activity of a given amount of a radioactive substance to decay to half of its initial value"
    position=center
    variable=t122
    format="0.000#"
    editable=t==0
    action=//t121=Math.min(k1,1000); //k1=Math.max(k1,0); //t121 = Math.log(2)/k1; k2 = Math.log(2)/t122; _initialize();
    columns=4
    size="40,24"
    tooltip="half life — symbol t1/2 — the time taken for the activity of a given amount of a radioactive substance to decay to half of its initial value"
    position=north
    text="s"
    tooltip="second"
    layout=BORDER:0,0
    position=west
    text=" $\\lambda$2 = "
    alignment=RIGHT
    tooltip="$\\lambda$2=k2 decay constant"
    position=center
    variable=k2
    format="0.000#"
    editable=t==0
    action=k1=Math.min(k1,1000); k1=Math.max(k1,0); _initialize();
    columns=4
    size="40,24"
    tooltip="dN3/dt= + k2*N2 Level 2 decay rate."
    layout=BORDER:0,0
    position=west
    text=" N3 = "
    alignment=RIGHT
    background=BLUE
    foreground=WHITE
    position=center
    variable=N3
    format="0"
    editable=false
    action=_initialize();
    columns=4
    size="40,24"
    tooltip="Lower state particle number."
    layout=HBOX
    borderType=LOWERED_ETCHED
    position=center
    layout=HBOX
    layout=HBOX
    position=west
    text=" t = "
    alignment=RIGHT
    position=center
    variable=t
    format="0.00##"
    editable=false
    action=_initialize()
    columns=4
    size="40,24"
    tooltip="Time."
    position=north
    text="s"
    tooltip="second"
    layout=HBOX
    position=west
    text=" $\Delta$t = "
    alignment=RIGHT
    position=center
    variable=dt
    format="0.00##"
    editable=t==0
    action=_initialize()
    columns=4
    size="40,24"
    tooltip="Time."
    position=north
    text="s"
    tooltip="second"
    position=east
    layout=HBOX
    variable=showWorld
    text="World"
    tooltip="Show the microscopic world view."
    position=east
    variable=showPlot
    text="plot"
    tooltip="Show the polulation as a function of time."
    variable=showTable
    text="table"
    position=west
    layout=HBOX
    position=center
    variable=_isPaused
    tooltip="Starts and stops the simulation."
    imageOn=/org/opensourcephysics/resources/controls/images/play.gif
    actionOn=_play()
    imageOff=/org/opensourcephysics/resources/controls/images/pause.gif
    actionOff=_pause()
    image=/org/opensourcephysics/resources/controls/images/step.gif
    action=_step()
    tooltip="Setp the simulation"
    image="/org/opensourcephysics/resources/controls/images/reset1.gif"
    action=_initialize();
    tooltip="Resets the time."
    image=/org/opensourcephysics/resources/controls/images/reset.gif
    action=_reset()
    tooltip="Reset the simulation"
    position=center
    layout=HBOX
    layout=HBOX
    visible=showWorld
    position=center
    autoscaleX=false
    autoscaleY=false
    minimumX=0
    maximumX=sampleSize
    minimumY=0
    maximumY=sampleSize
    square=true
    visible=showWorld
    x=x
    y=y
    sizeX=particleDiameter
    sizeY=particleDiameter
    fillColor=colors
    layout=VBOX
    layout=VBOX
    visible=showPlot
    tooltip="Three-State Decay Plot"
    autoscaleX=true
    autoscaleY=true
    maximumX=t121
    titleX="t"
    titleY=%yTitle%
    inputX=t
    inputY=n1
    visible=plotMode!=2 && !plotChange
    measured= !plotChange
    norepeat=true
    lineColor=255,128,128,255
    lineWidth=2
    xLabel="t"
    yLabel="n1"
    inputX=t
    inputY=n2
    visible=plotMode!=2&& !plotChange
    measured=!plotChange
    norepeat=true
    lineColor=128,255,128,255
    lineWidth=2
    xLabel="t"
    yLabel="n2"
    inputX=t
    inputY=n3
    visible=plotMode!=2 && !plotChange
    measured= !plotChange
    norepeat=true
    lineColor=128,128,255,255
    lineWidth=2
    xLabel="t"
    yLabel="n3"
    inputX=t
    inputY=N1
    visible=plotMode!=1 && !plotChange
    measured= !plotChange
    norepeat=true
    lineColor=RED
    lineWidth=2
    xLabel="t"
    yLabel="N1"
    inputX=t
    inputY=N2
    visible=plotMode!=1 && !plotChange
    measured= !plotChange
    norepeat=true
    lineColor=GREEN
    lineWidth=2
    xLabel="t"
    yLabel="N2"
    inputX=t
    inputY=N3
    visible=plotMode!=1 && !plotChange
    measured= !plotChange
    norepeat=true
    lineColor=BLUE
    lineWidth=2
    xLabel="t"
    yLabel="N3"
    x=t
    y=dN1
    visible=plotMode!=1 && plotChange
    measured=plotChange
    norepeat=true
    connected=false
    style=BAR
    markersize=6
    secondaryColor=RED
    x=t
    y=dN2
    visible=plotMode!=1 && plotChange
    measured=plotChange
    norepeat=true
    connected=false
    style=BAR
    markersize=6
    secondaryColor=0,255,0,182
    inputX=t+dt
    inputY=n1*p1
    visible=plotMode!=2 && plotChange
    measured=plotChange
    norepeat=true
    lineColor=PINK
    lineWidth=2
    xLabel="t"
    yLabel="$\Delta$n1"
    inputX=t+dt
    inputY=n2*p2+n1*p13
    visible=plotMode!=2 && plotChange
    measured=plotChange
    norepeat=true
    lineColor=192,255,0
    lineWidth=2
    xLabel="t"
    yLabel="$\Delta$n1"
    numberOfElements=n
    x=t121x
    y=0
    sizeX=0
    sizeY=n1s
    visible=halflife
    lineColor=ORANGE
    numberOfElements=n
    x=0
    y=n1s
    sizeX=n1x
    sizeY=0
    visible=halflife
    lineColor=ORANGE
    layout=FLOW:center,6,0
    borderType=LOWERED_ETCHED
    position=center
    text="continuous"
    noUnselect=true
    action=plotMode=1
    position=north
    text="discrete"
    noUnselect=true
    action=plotMode=2
    position=south
    text="both"
    noUnselect=true
    action=plotMode=0
    variable=plotChange
    text="$\Delta$N"
    actionon=yTitle="$\\Delta$N1,$\\Delta$N2";
    actionoff=yTitle="N1,N2,N3";
    variable=halflife
    text="halflife"
    background=ORANGE
    tooltip="halflife"
    layout=VBOX
    visible=showTable
    tooltip="Three-State Decay Table"
    input=new double[]{t,N1,N2,N3,dN1,dN2}
    maxPoints=1000
    norepeat=true
    stride=stride
    showRowNumber=true
    columnNames="row#,t,N1,N2,N3,$\\Delta$N1,$\\Delta$N2"
    columnFormat="0,0.0##,0,0,0,0,0"
    background=WHITE
    tooltip="Three-State Decay Table"
    layout=border
    position=west
    image="/org/opensourcephysics/resources/controls/images/erase.gif"
    action=_view.dataTable.clearData(); _view.dataTable.appendRow(new double[]{t,N1,N2,N3});
    tooltip="Clears the table data."
    position=east
    layout=border
    position=west
    text="stride = "
    tooltip="The stride between data points."
    position=center
    variable=stride
    format="0"
    action=stride=Math.max(1,stride);
    size="50,24"