# Changing a Constant Based on Certain Radius

I'm trying to change my Mu based on the size of my spherical radius but cannot seem to get the code right. I've tried numerous ways but end up either with only one Mu (ex. Mu=21) in the end or code that runs forever. The final table is what I'm using to see if my code is correct - if Mu is changing based on the radius then the third column should have different values based on the second column.

If anyone has any recommendations I would greatly appreciate it.

Subscript[f, x][x_, y_, z_, xnudge_, ynudge_, znudge_,
t_] := \[Sigma] (y - x);
Subscript[f, y][x_, y_, z_, xnudge_, ynudge_, znudge_, t_] :=
x (-\[Sigma] - z) - y;
Subscript[f, z][x_, y_, z_, xnudge_, ynudge_, znudge_, t_] :=
x y - \[Beta] z - \[Beta] (\[Rho] + \[Sigma]);

Subscript[
\!$$\*OverscriptBox[\(f$$, $$~$$]\), x][x_, y_, z_, xnudge_, ynudge_,
znudge_, t_] :=
\[Sigma] (ynudge - xnudge) - (\[Mu] (xnudge - x));
Subscript[
\!$$\*OverscriptBox[\(f$$, $$~$$]\), y][x_, y_, z_, xnudge_, ynudge_,
znudge_, t_] :=
xnudge (-\[Sigma] - znudge) -
ynudge - (Subscript[\[Mu], 0] (ynudge - y));
Subscript[
\!$$\*OverscriptBox[\(f$$, $$~$$]\), z][x_, y_, z_, xnudge_, ynudge_,
znudge_, t_] :=
xnudge ynudge - \[Beta] znudge - \[Beta] (\[Rho] + \[Sigma]) - \
(Subscript[\[Mu], 0] (znudge - z));

\[Mu] = RandomReal[{18, 24}];

For[i = 1, i <= tMax, i++,
{

If[{Sqrt[((x[i])^2) + ((y[i])^2) + ((z[i])^2)] <= 10},
Replace[\[Mu], \[Mu] -> 18]];
If[{10 < Sqrt[((x[i])^2) + ((y[i])^2) + ((z[i])^2)] <= 20},
Replace[\[Mu], \[Mu] -> 19]];
If[{20 < Sqrt[((x[i])^2) + ((y[i])^2) + ((z[i])^2)] <= 30},
Replace[\[Mu], \[Mu] -> 22]];
If[{30 < Sqrt[((x[i])^2) + ((y[i])^2) + ((z[i])^2)] <= 40},
Replace[\[Mu], \[Mu] -> 24]];
If[{40 < Sqrt[((x[i])^2) + ((y[i])^2) + ((z[i])^2)] <= 50},
Replace[\[Mu], \[Mu] -> 24]];
If[{50 < Sqrt[((x[i])^2) + ((y[i])^2) + ((z[i])^2)] <= 55},
Replace[\[Mu], \[Mu] -> 24]];
If[{55 < Sqrt[((x[i])^2) + ((y[i])^2) + ((z[i])^2)]},
Replace[\[Mu], \[Mu] -> 24]];

}];

Subscript[\[Mu], 0] = 0;

\[Sigma] = 10;
\[Rho] = 28;
\[Beta] = 8/3;
k = (\[Beta]^2 (\[Rho] + \[Sigma])^2)/(4 (\[Beta] - 1));

t[0] = 0;
tMax = 20000;
\[Delta]t = 0.001;

(*For Deterministic*)
\[Theta] = RandomReal[{0, 2 \[Pi]}];
\[Phi] = RandomReal[{0, \[Pi]}];
r = 25;

x[0] = r Cos[\[Theta]] Sin[\[Phi]];
y[0] = r Sin[\[Theta]] Cos[\[Phi]];
z[0] = r Cos[\[Phi]];

(*For Nudge*)
Subscript[\[Theta], 0] = 0;
Subscript[\[Phi], 0] = 0;
Subscript[r, 0] = 0;

xnudge[0] =
Subscript[r, 0]
Cos[Subscript[\[Theta], 0]] Sin[Subscript[\[Phi], 0]];
ynudge[0] =
Subscript[r, 0]
Sin[Subscript[\[Theta], 0]] Cos[Subscript[\[Phi], 0]];
znudge[0] = Subscript[r, 0] Cos[Subscript[\[Phi], 0]];

Do[{
t[n] = t[0] + \[Delta]t n,
Subscript[k,
x] = \[Delta]t Subscript[f, x][x[n], y[n], z[n], xnudge[n],
ynudge[n], znudge[n], t[n]];
Subscript[k,
y] = \[Delta]t Subscript[f, y][x[n], y[n], z[n], xnudge[n],
ynudge[n], znudge[n], t[n]];
Subscript[k,
z] = \[Delta]t Subscript[f, z][x[n], y[n], z[n], xnudge[n],
ynudge[n], znudge[n], t[n]];

Subscript[
\!$$\*OverscriptBox[\(k$$, $$~$$]\), x] = \[Delta]t Subscript[
\!$$\*OverscriptBox[\(f$$, $$~$$]\), x][x[n], y[n], z[n], xnudge[n],
ynudge[n], znudge[n], t[n]];
Subscript[
\!$$\*OverscriptBox[\(k$$, $$~$$]\), y] = \[Delta]t Subscript[
\!$$\*OverscriptBox[\(f$$, $$~$$]\), y][x[n], y[n], z[n], xnudge[n],
ynudge[n], znudge[n], t[n]];
Subscript[
\!$$\*OverscriptBox[\(k$$, $$~$$]\), z] = \[Delta]t Subscript[
\!$$\*OverscriptBox[\(f$$, $$~$$]\), z][x[n], y[n], z[n], xnudge[n],
ynudge[n], znudge[n], t[n]];

x[n + 1] = x[n] + Subscript[k, x];
y[n + 1] = y[n] + Subscript[k, y];
z[n + 1] = z[n] + Subscript[k, z];

xnudge[n + 1] = xnudge[n] + Subscript[
\!$$\*OverscriptBox[\(k$$, $$~$$]\), x];
ynudge[n + 1] = ynudge[n] + Subscript[
\!$$\*OverscriptBox[\(k$$, $$~$$]\), y];
znudge[n + 1] = znudge[n] + Subscript[
\!$$\*OverscriptBox[\(k$$, $$~$$]\), z];

},

{n, 0, tMax}]

MatrixForm[
Table[{t[i], Sqrt[((x[i])^2) + ((y[i])^2) + ((z[i])^2)], \[Mu]}, {i,
0, 100}]]


This is my first time posting here - I'm sorry if my code isn't properly formatted.

• Please do not post images of your work, especially when the images display at a size that make them difficult to read. Please post your actual Mathematica code in the form of text that can be copied and pasted into a Mathematica notebook. Without such, it will be difficult to reproduce your problem and to experiment with possible solutions. – m_goldberg Apr 29 at 16:26
• @BobSacamano Use mu[r_] := Piecewise[{{18, 0 <= r <= 10}, {19, 10 < r <= 20}, {22, 20 < r <= 30}, {24, True}}] – Alex Trounev Apr 29 at 18:29