Stop different Manipulate Panels from triggering each other - wolfram-mathematica

This should be a simple question, but I have given up on it after a while now.
I have different input lines which I have evaluated in a single notebook. Two of these have manipulate statements:
The first one
Manipulate[{ Some Plot Func }, {{\[Omega]0, 3}, 0, 3}, {{\[Tau], 5}, -1, 20}]
The second One:
Manipulate[{ Some Plot Func }, {Twave, 1, 10}, {{Tenv, 10}, 0, 100}, TrackedSymbols :> True]
When I change parameters in the second one, i can see the first one evaluating as well.
I have tried specifying with TrackedSymbols to disentangle the two, but this does not succeed. I hope someone can point me to the obvious solution. It is slowing down evaluation a lot.
Thank you!

How about this?
End each of your manipulates with a semicolon.
Create a third "master" manipulate which does not end with a semicolon.
Within the master manipulate, use a TabView. With each pane of the tab, run one of your manipulates by calling it like a function. It is convenient to create a list of your manipulates and pick the one to execute with a "tab index" of sorts.
I've gotten this to work well with several manipulates, rules for moving between them via the tabs, and so forth. It's proven to be a useful approach for notebook applications,as the complexity of one giant manipulate gets out of hand.

Related

How to sort text columns in a specific manner?

I was wondering if it was possible to have a way to sort text rows in a specific manner. What I mean by that is, imagine we have a column of 15 rows which could contain :
Foo
Bar
Something
Other_example
We want to be able to sort them in this particular order. The easy option I found was to put numbers in front of them (1 - Foo, 2 - Bar, etc) and then sorting them in a normal (alphanumerical) manner, but that is not really visually appealing, I would say.
Is there another way to do it simply ? For example by "hiding" the numbers, or something else ? Of course I could write a script for it with with a condition such as a switch-case, but that wouldn't be truly what I am looking for and easily done within the spreadsheet itself (I think so at least, I have never really gone far in sheets possibilities). However if there is no other option, I will do it and add a simple button to access the script, I guess.
Thank for your time !
Sanimys
=ARRAYFORMULA(ARRAY_CONSTRAIN(SORT(IFERROR(
VLOOKUP(C2:C, {A2:A, ROW(A2:A)}, {1, 2}, 0)), 2, 1), 999^99, 1))

How to display name of variables in plots in Mathematica

Hi guys I have a list of 2-D coordinates that I assigned one to one to a list of variables (i.e. x[i]), but i want show the variable names on list plots but don't know how to.
Please help. Thank you!
When you want Mathematica's default behavior, for example: a variable name is immediately replaced with the value assigned to that variable, things are often fairly simple. But when you want to change that default behavior things are usually much more complicated.
Try this
values = {{1, 5}, {2, 7}, {3, 4}};
SetAttributes[fun, {HoldFirst, Listable}];
fun[v_] := ToString[Unevaluated[v]];
g1 = Show[ListPlot[values],
Graphics[Text[#[[1]], #[[2]], {0, 1}] & /#
Transpose[{Flatten[fun[{x[1], x[2], x[3]}]], values}]]]
Usually I recommend new users study each part of an answer, read the help pages, take it apart, see how each piece works, make little changes until you understand how you can adapt that in the future. But in this case I think just hope that it works for you as is.
You may use the Labeled data wrapper syntax of ListPlot.
With
values = {{1, 5}, {2, 7}, {3, 4}};
then
ListPlot[
MapIndexed[Labeled[#1, StringJoin["x[", ToString#First##2, "]"]] &]#values
]
Hope this helps.

How to run initialization code for a palette?

Occasionally it would be preferable to have some initialization code for palettes (of buttons). For example, it could define some functions that are used by palette buttons.
What is the easiest and preferable way to define/run initialization code for a palette?
The initialization can run either when the palette is loaded or when any button is pressed for the first time (possible issue: what if the kernel is restarted after the palette was loaded?)
The definitions should be somehow localized (i.e. in their own context -- do unique notebook contexts help here?)
If possible, I'd prefer a minimal effort solution (i.e. extra code at the fewest possible places, self contained palette file with no extra package files, palette creation using the existing convenience tools of palettes menu or CreatePalette, etc.)
(You can assume that the initialization code runs fast, e.g. it consists of definitions only)
You're right to be concerned about the visibility of the Dynamic being an issue. The way to absolutely guarantee a Dynamic expression to be evaluated regardless of the visibility of any of the individual cells is to use NotebookDynamicExpression. Here's an example that illustrates NotebookDynamicExpression working while a Dynamic fails because it's hidden within a closed cell group:
cell1 = First # MakeBoxes[
TextCell["Click to open", "Title",
CellMargins -> 0, System`WholeCellGroupOpener -> True],
StandardForm];
cell2 = First # MakeBoxes[
ExpressionCell[DynamicWrapper["hidden cell", Print["DynamicWrapper"]]],
StandardForm];
CreatePalette[
Notebook[{Cell[CellGroupData[{cell1, cell2}, Closed]]},
NotebookDynamicExpression :>
Dynamic[Refresh[Print["NotebookDynamicExpression"], None]]]]
When you evaluate this, note that the Dynamic in NotebookDynamicExpression evaluates immediately. The DynamicWrapper never evaluates until you open the cell group, which you can do by clicking on the "Click to open" text.
In this example, incidentally, notice that I wrapped the NotebookDynamicExpression with Refresh. The function Refresh[#, None]& will make sure that the code evaluates only once -- when the notebook is first opened. Otherwise, the code would obey the standard properties of Dynamic and evaluate whenever any of the dependencies change.
NotebookDynamicExpression has been around since v6, but was only documented in v8. Also documented are its related cousins, CellDynamicExpression and FrontEndDynamicExpression.
A DynamicBox with Initialization is capable of the basic function. You can size the palette such that the object is not visible, and it will still operate.
Here is code for a small sample palette. It sets a value for var. The active code is offset with whitespace.
(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[{
TagBox[GridBox[{
{
ButtonBox["\<\"TSV\"\>",
Appearance->Automatic,
ButtonFunction:>None,
Evaluator->Automatic,
Method->"Preemptive"]},
{
ButtonBox["\<\"CSV\"\>",
Appearance->Automatic,
ButtonFunction:>None,
Evaluator->Automatic,
Method->"Preemptive"]},
{
ButtonBox["\<\"Table\"\>",
Appearance->Automatic,
ButtonFunction:>None,
Evaluator->Automatic,
Method->"Preemptive"]}
},
GridBoxAlignment->{"Columns" -> {{Left}}},
GridBoxItemSize->{"Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}],
"Column"], "\[IndentingNewLine]",
DynamicBox[Null,
Initialization :> ($CellContext`var = "It is done, Master.")
]
}], NotebookDefault,
CellMargins->{{0, 0}, {0, 0}},
CellBracketOptions->{"Color"->RGBColor[0.269993, 0.308507, 0.6]},
CellHorizontalScrolling->True,
PageBreakAbove->True,
PageBreakWithin->False,
ShowAutoStyles->True,
LineSpacing->{1.25, 0},
AutoItalicWords->{},
ScriptMinSize->9,
ShowStringCharacters->False,
FontFamily:>CurrentValue["PanelFontFamily"],
FontSize:>CurrentValue["PanelFontSize"]]
},
WindowSize->{55, 105},
WindowMargins->{{Automatic, 583}, {Automatic, 292}},
WindowFrame->"Palette",
WindowElements->{},
WindowFrameElements->{"CloseBox", "MinimizeBox"},
StyleDefinitions->"Palette.nb"
]
(* End of Notebook Content *)

How to extract only the data points from BodePlot plot?

I am trying to fix the Phase plot part of BodePlot, as it does not wrap correctly. And there is no option that I can use to tell it to wrap.
So, instead of doing the full plot myself, (I can do that if I have to) I am thinking of first making the BodePlot, grab the data points, do the wrapping on the data (once I get the x,y data, the rest is easy), then I need to put the new list of points back into the plot, and then use Show to display it.
The part I am stuck at, is extracting the points from FullForm. I can't get the correct Pattern to do that.
This is what I go to so far:
hz=z/(z^2-z+0.3);
tf=TransferFunctionModel[hz,z,SamplingPeriod->2];
phasePlot=BodePlot[tf,{0.001,2 Pi},
ScalingFunctions->{Automatic,{"Linear","Degree"}},PlotLayout->"List"][[2]]
You see how it does not wrap at 180 degrees. It is more common in dsp that Bode phase plot wraps. Here is what it 'should' look like:
So, this is what I did:
FullForm[phasePlot]
Graphics[List[
List[List[], List[],
List[Hue[0.67, 0.6, 0.6],
Line[List[List[0.0010000243495554542, -0.2673870119911639],
List[0.0013659538057574799, -0.36521403872250247],
List[0.0017318832619595053, -0.46304207336414027],
....
I see the data there (the x,y) But how to pull them out? I tried this:
Cases[FullForm[phasePlot], List[x_, y_] -> {x, y}, Infinity];
But the above matches in addition to the list of point, other stuff that I do not need.
I tried many other things, but can't get only the list of points out.
I was wondering if someone knows how to pull only the (x,y) points from the above plot. Is there a better way to do this other than using FullForm?
Thanks
Update:
I just find a post here which shows how to extract data from plot. So I used it:
points = Cases[Normal#phasePlot, Line[pts_] -> pts, Infinity]
You could do try nesting the replacement rules, for example
phase2 = phasePlot /.
Line[a_] :> (Line[a] /. {x_?NumericQ, y_?NumericQ} :> {x, Mod[y, 360, -180]});
Show[phase2, PlotRange -> {Automatic, {-180, 180}}, FrameTicks -> Automatic]
Output:
The list you are looking for appears to be wrapped by Line[], and it seems to be the only case in your plot. So you could use
Cases[phasePlot, Line[list_] :> list, Infinity]
Edit:
When I posted my response, the page refreshed and I saw that you came across precisely what I had proposed. I'll leave my response posted here anyway.
Edit2:
Szabolics pointed out that FullForm[] has no effect, so I removed it from my original posting.

Mathematica: AbsoluteOptions not working properly

According to the documentation AbsoluteOptions[expr,name] "gives the absolute setting for the option name".
"AbsoluteOptions gives the actual settings for options used internally by Mathematica when the setting given is Automatic or All."
Here is an example they show:
<< AbsoluteOptions[Plot[Sin[x], {x, 0, 2 Pi},
PlotRange -> Automatic], PlotRange]
>> {PlotRange -> {{0., 6.28319}, {-1., 1.}}}
Here I use << to denote Input and >> to denote output.
This seems to work fine. However, when I try to obtain the AspectRatio of a plot it simply gives me Automatic. Try this,
AbsoluteOptions[
ListPlot3D[{{1, 1, 1, 1}, {1, 2, 1, 2}, {1, 1, 3, 1}, {1, 2, 1, 4}},
AspectRatio -> Automatic],
AspectRatio
]
Similar format as the example they show but the output I get is simply
{AspectRatio->Automatic}
Does this mean that the argument expr can only be a Graphics object and not Graphics3D? This doesn't make sense because it works fine if I try to obtain the PlotRange of a Graphics3D object. Is this a bug or my mathematica is broken? Another thing could be that the documentation is not being very specific. Which one is it?
Here is a link to the documentation:
http://reference.wolfram.com/mathematica/ref/AbsoluteOptions.html
I'm using Mathematica 7.0.1.0.
You can apply ImageDimensions directly to Graphics3D to get its ImageSize.
It seems that AbsoluteOptions just was not modified since Mathematica 4 (see bottom of the corresponding documentation page). This function is very buggy (often gives wrong value for PlotRange for 2D graphics generated by Show, for example) and sometimes does not work at all as you pointed in your question. Compare it with FullOptions and FullGraphics those are seemed to be not modified since version 2... Sometimes FullOptions gives right value when AbsoluteOptions gives wrong or does not work at all.
Maybe, BoxRatios is the one you are looking for. HTH.

Resources