(*  z2kuvaus.nb   
   FT2012,  EeHa  *)

Complex2Pair[z_]:={Re[z],Im[z]};
MyMapping[z_]:=z^2;

MyCircle[center_,r_,t_]:=center+r*Exp[t*2*Pi*I];
MyCirclePointTable[center_,r_,div_]:=Table[Complex2Pair[MyCircle[center,r,(i/myCircleDiv)]],{i,0,myCircleDiv}];
MyCircleImagePointTable[center_,r_,div_]:=Table[Complex2Pair[MyMapping[MyCircle[center,r,(i/myCircleDiv)]]],{i,0,myCircleDiv}];

myCenter=-0.25;
myRadius=1.;
myCircleDiv=200.;
myCirclePointTable=MyCirclePointTable[myCenter,myRadius,myCircleDiv];
myCircleImagePointTable=MyCircleImagePointTable[myCenter,myRadius,myCircleDiv];

myDomainGfx=ListLinePlot[myCirclePointTable,AspectRatio->1,Filling->Axis];
myImageGfx=ListLinePlot[myCircleImagePointTable,AspectRatio->1,Filling->Axis];
{myDomainGfx,myImageGfx}

Manipulate[{ListLinePlot[myCirclePointTable,AspectRatio->1,Epilog->{AbsolutePointSize[5],Point[{u,v}]},PlotLabel->Row[{"z = u + iv = ",u," + ",v," i"}],Filling->Axis],ListLinePlot[myCircleImagePointTable,AspectRatio->1,Filling->Axis]
},{{u,Re[myCenter]},Re[myCenter]-myRadius,Re[myCenter]+myRadius},{{v,Im[myCenter]},Im[myCenter]-myRadius,Im[myCenter]+myRadius}]

uValueRange=Module[{tab=Table[{myCircleImagePointTable[[i]][[1]]},{i,1,myCircleDiv+1}]},{Min[tab],Max[tab]}];
vValueRange=Module[{tab=Table[{myCircleImagePointTable[[i]][[2]]},{i,1,myCircleDiv+1}]},{Min[tab],Max[tab]}];

(* Päähaaran alkukuvapiste on sininen ympyrän sisällä, harmaa sen ulkopuolella *)
MyInvMappingBranch1[z_]:=z^(1/2);
(* Toisen haaran alkukuvapiste on punainen *)
MyInvMappingBranch2[z_]:=-z^(1/2);

Manipulate[GraphicsRow[{ListLinePlot[myCirclePointTable,AspectRatio->1,Epilog->{AbsolutePointSize[7],If[Abs[MyInvMappingBranch1[u+I*v]-myCenter]≤myRadius,Blue,Gray],Point[Complex2Pair[MyInvMappingBranch1[u+I*v]]],Red,Point[Complex2Pair[MyInvMappingBranch2[u+I*v]]]},PlotLabel->Row[{"z_1, z_2"}],Filling->Axis],ListLinePlot[myCircleImagePointTable,AspectRatio->1,Epilog->{AbsolutePointSize[5],Point[{u,v}]},PlotLabel->Row[{z^2," = u + iv = ",SetPrecision[u,3]," + ",SetPrecision[v,3]," i"}],Filling->Axis]}],{{u,(uValueRange[[1]]+uValueRange[[2]])/2},uValueRange[[1]],uValueRange[[2]]},{{v,(vValueRange[[1]]+vValueRange[[2]])/2},vValueRange[[1]],vValueRange[[2]]}]