# Use While loop (run code until both conditions are satisfied)?

Posted 5 months ago
486 Views
|
|
1 Total Likes
|
 Hello, I have an error while using "while" loop (I want the code to run until both condition satified:xx +zz =2 && yy +ww =0.any suggestions?Here's the code: ClearAll[Y ,X,z,w]; T0=1 ; Hmu=0.8; SA=10+Hmu ; SB=10-Hmu; Sigma=1.5; K=10; r=1.02; gamma=0.1; Vi=2; Eye=2; ZC=(K-SA)/Sigma; ZB=(K-SB)/Sigma ; S0=(SA-gamma(Sigma^2)(Vi /Eye ))/r C0=((SA-gamma(Sigma^2)(Vi /Eye ) -K)(1-CDF[NormalDistribution[0, 1], ZC+gamma*Sigma*(Vi /Eye ) ])+(PDF[NormalDistribution[0, 1], ZC+gamma*Sigma*(Vi /Eye ) ])Sigma)/r xx=0; zz=0; while[xx +zz =2 && yy +ww =0] A=(((Vi /Eye ) -X)S0-Y*C0)r+X*SA-(gamma/2)(X^2)(Sigma^2) B=(((Vi /Eye ) -X)S0-Y*C0)r +(X +Y)SA -(gamma/2)((X +Y) ^2)(Sigma^2) -Y *K Q=(((Vi /Eye ) -z)S0-w*C0)r+z*SB-(gamma/2)(z^2)(Sigma^2) P=(((Vi /Eye ) -z)S0-w*C0)r +(z +w)SB -(gamma/2)(z +w) ^2(Sigma^2) -w *K UA=-Exp[-gamma*A]*(CDF[NormalDistribution[0, 1], ZC+gamma*X *Sigma ]) -Exp[-gamma*B]*(1-CDF[NormalDistribution[0, 1], ZC+gamma*(X +Y )*Sigma ]) UB=-Exp[-gamma*Q ]*(CDF[NormalDistribution[0, 1], ZB+gamma*z *Sigma ]) -Exp[-gamma*P ]*(1-CDF[NormalDistribution[0, 1], ZB+gamma*(z+w )*Sigma ]) AMAX=Maximize[UA ,{X >=0,X<=2,Y>=-1,Y<=1},{X ,Y}] BMAX=Maximize[UB ,{z >=0,z<=2,w>=-1,w<=1},{z ,w}] xx=Replace[X,AMAX [[2,1]]] yy=Replace[Y,AMAX [[2,2]]] zz=Replace[z,BMAX [[2,1]]] ww=Replace[w,BMAX [[2,2]]] If[xx +zz<2,S0=S0-0.001,If[xx+zz>2,S0,S0+0.001,S0]] If[yy +ww<0,C0=C0-0.001,If[yy+ww>0,C0,C0+0.001,C0]] 
Sort By:
Posted 5 months ago
 Hello,Functions in Mathematica, including While, are always written with a first capital letter, so while[xx +zz =2 && yy +ww =0] isn't recognized as anything useful by the language.There are a few other syntax issues in your code, particularly with your While expression. I'd recommend spending time on the While documentation page to help you identify what else could be going wrong.
Community posts can be styled and formatted using the Markdown syntax.