Message Boards Message Boards

Several errors from copied NDSolve code

Can anyone help me with this code, I copied it from some textbook but it is not working the way it

4 Replies

Dear Bill Nelson, Thank you so much. I never had imagined Mathematica can do this, hope my students will enjoy this! Thank you once again

Posted 4 months ago

Try the following changes

k1f=0.5;k1r=0.2;k2f=0.5;k2r=(k1r/k1f)*k2f;k3f=1.5;k3r=10^-3;tmax=1;
S=1.25;T=S;P=0.5;
R1f:=k1f*S*T;R1r:=k1r*XL[t];
R2f:=k2f*S*T*XL[t];R2r:=k2r*(XL[t])^2;
R3f:=k1f*S*T;R3r:=k1r*XD[t];
R4f:=k2f*S*T*XD[t];R4r:=k2r*(XD[t])^2;
R5f:=k3f*XL[t]*XD[t];R5r:=k3r*P;
Soln1=NDSolve[{XL'[t]\[Equal]R1f-R1r+R2f-R2r-R5f+R5r,XD'[t]\[Equal]R3f-R3r+R4f-R4r-R5f+R5r,XL[0]\[Equal]0.2502,XD[0]\[Equal]0.2500},{XL[t],XD[t]},{t,0,2000},MaxSteps->10000];
Plot[Evaluate[{XL[t],XD[t]}/.Soln1],{t,0,tmax},AxesLabel->{"time","[XL]&[XD]"},AxesStyle->Directive[Black,14],PlotStyle->{{Black,Thick},{Gray,Thick}},PlotRange->All]
POSTED BY: Bill Nelson

Dear Bill Nelson, Thank you so much! it really works! Can you suggest how i can put animate command in this code so that my output is an animation with respect to variable t in the code

Posted 4 months ago

Try

k1f=0.5;k1r=0.2;k2f=0.5;k2r=(k1r/k1f)*k2f;k3f=1.5;k3r=10^-3;
S=1.25;T=S;P=0.5;
R1f:=k1f*S*T;R1r:=k1r*XL[t];
R2f:=k2f*S*T*XL[t];R2r:=k2r*(XL[t])^2;
R3f:=k1f*S*T;R3r:=k1r*XD[t];
R4f:=k2f*S*T*XD[t];R4r:=k2r*(XD[t])^2;
R5f:=k3f*XL[t]*XD[t];R5r:=k3r*P;
Animate[
Soln1=NDSolve[{XL'[t]\[Equal]R1f-R1r+R2f-R2r-R5f+R5r,XD'[t]\[Equal]R3f-R3r+R4f-R4r-R5f+R5r,XL[0]\[Equal]0.2502,XD[0]\[Equal]0.2500},{XL[t],XD[t]},{t,0,2000},MaxSteps->10000];
Plot[Evaluate[{XL[t],XD[t]}/.Soln1],{t,0,tmax},AxesLabel->{"time","[XL]&[XD]"},AxesStyle->Directive[Black,14],PlotStyle->{{Black,Thick},{Gray,Thick}},PlotRange->{{0,.9},{.25,.75}}],
{tmax,0,1}]
POSTED BY: Bill Nelson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract