Sample code 5.3 for magnetic field, Chapter 5 on Biot-Savart law and Simpson’s rule

SetDirectory["C:\\Users\\Yoon\\Documents\\teaching\\ZCE111\\1011SEM2\\notes\\lecture5\\BiotSavart"];(*The "SetDirectory" line has to be modified to point to your directory,if you are to run it in your own PC*)

(*Instruction: *)
(*Provide the value of L, then run initialisation.m and 525.m in sequence. The outcome is tabulated in the form of tBy. Rename tBy for the particular value of L
*)


(* Run L = 1.0 ****************************************************)
L=1.0;(*Must provide L before running initialisation.m*)
<<initialisation.m;
<<525.m;
tByL1=tBy;
(* Run L = 1.0 ****************************************************)



(* Run L = 10.0 ****************************************************)
L=10.0;(*Must provide L before running initialisation.m*)
<<initialisation.m;
<<525.m;
tByL10=tBy;
(* Run L = 10.0 ****************************************************)


ListPlot[{tByL1,tByL10},Joined->True,PlotMarkers->Automatic,PlotStyle->{Red,Blue},AxesLabel-> {"x","By"}];

(*Now generate By according to analytical solution*)
ByAnl[xdum_]:=(mu0I/(2*Pi*xdum));
tByAnl=Table[{xini+i*Deltax,ByAnl[xini+i*Deltax]},{i,0,NStepx}];
(*Print[
ListPlot[{tByL1,tByL10,tByAnl},Joined->True,PlotMarkers->Automatic,PlotStyle->{Red,Blue,Green},AxesLabel-> {"x","By"},PlotRange->{0,4}]];*)



(*Sample code 5.3 for simpson's rule*)
L=10;
<<initialisation.m;
<<simpson.m;
tBysimpL10=tBysimp;
Print[
ListPlot[{tBysimpL10,tByL10,tByAnl},Joined->True,PlotMarkers->Automatic,PlotStyle->{Red,Blue,Green},AxesLabel-> {"x","By"},PlotRange->{0,4}]];