I have a series of variables that will plot the number of straight segments along a curve, thanks to the help from here on one of my previous questions.
I can create a working Manipulate command from the code in Mathematica by varying nSeg and then visually show the number of segments increasing as the slider is raised, similar to the picture below.
The number of segments (nSeg) can affect the number of x co-ordinates that I have, so if nSeg = 4 then I will have nSeg+1 x co-ordinates in total.
The difficulty I have is that because I am using subscripted variables for my x co-ordinates, if I try to reset them using the code below or through using Remove[] I invoke dynamic content in my Mathematica file and I'm unable to export as a CDF file that I can embed into a website, although I can get it to execute as a CDF if the user specifically selects to allow dynamic content.
clearSubscript[x_Symbol] := (First /@ Select[DownValues[Subscript],
MatchQ[First[#],
Verbatim[HoldPattern][Subscript[x, _]]] &]) /.
HoldPattern :> Unset;
clearSubscript[x];
I've been hunting around for ways to remove subscripted variables for a few days now, and whilst I've found a few different ways of doing it, I've not managed to work out how this can be done in a way that doesn't invoke Dynamic Content in Mathematica, and without doing this I'm struggling to create a CDF that can be embedded into a webpage.
Any suggestions or help, gratefully received...
EDIT: Removing all subscripts I still get a similar problem when trying to clear variables, edited to include simplified sample code below which I can't make into CDF file for embedding into a web page due to the Dynamic Content which I think is being invoked by the Clear command.
Manipulate[
nSeg;
f[x_] = (50 x)/41 - x^2/3362;
upVal = 4100;
chordL = Table[Sqrt[(x[i + 1] - x[i])^2 + (f[x[i + 1]] - f[x[i]])^2], {i, 1, nSeg}];
combEqs = # == d & /@ chordL;
Clear[vars, x];
vars = Append[{x[#], #, x[1] + 10^-6, upVal - 10^-6} & /@ Range[2, nSeg], {d, 1}];
x[1] = 0;
x[nSeg + 1] = upVal;
sol = {FindRoot[combEqs, vars]},
{nSeg, 3, 8, 1}
]
Question updated to reflect the intention is to enable the Manipulate to recreate the graphical images above of the cable-chain arches, whilst I have no problems sharing the full code, I think it would be unfair to throw it all in here, but essentially there is a Plot function that plots the curves once the co-ordinates are calculated via the FindRoot, and the various solutions from the Findroot are also used to plot the links as straight lines. Combined with the proposed Dynamic and TrackedSymbols functions added, the code is something along the lines of:
Dynamic[
Manipulate[nSeg;
f[x_] = (50 x)/41 - x^2/3362;
upVal = 4100;
chordL = Table[Sqrt[(x[i + 1] - x[i])^2 + (f[x[i + 1]] - f[x[i]])^2], {i, 1, nSeg}];
combEqs = # == d & /@ chordL;
vars = Append[{x[#], #, x[1] + 10^-6, upVal - 10^-6} & /@ Range[2, nSeg], {d, 1}];
combEqs = combEqs /. {x[1] -> 0, x[nSeg + 1] -> upVal};
vars = vars /. {x[1] -> 0, x[nSeg + 1] -> upVal};
sol = {FindRoot[combEqs, vars]};
Show[Plot[f[x], {x, 0, 4100}],
Graphics[{Black, Thick,Line[Table[{{x[i], f[x[i]]}, {x[i + 1], f[x[i + 1]]}}, {i, 1, nSeg}] /. sol[[1]]]}],
Graphics[{Black, Dashed,Line[Table[{{x[i], f[x[i]]}, {x[i + 2], f[x[i + 2]]}}, {i, 1, nSeg - 1}] /. sol[[1]]]}],
Graphics[{Red, PointSize[Large],Point[Table[{x[i], f[x[i]]}, {i, 1, nSeg + 1}] /. sol[[1]]]}],
AspectRatio -> Automatic,
Axes -> False],
{nSeg, 3, 8, 1},
TrackedSymbols :> {nSeg}]]
x[5]
type DownValues. $\endgroup$