Mathematica Asked on September 1, 2021
I have the following multiplication Manipulate
:
Manipulate[
x*y,
{x, 1, 10},
{y, 5, 15}
];
When you run this Manipulate
, the X and Y sliders should not be visible to the user. But, The question: What is your X value between 1 and 10? should pop up with an empty box for entering a number for X between 1 and 10. After entering an X value, then the second question: What is your Y value between 5 and 15? should pop up with another empty box for entering a Y value. After answering both questions, the answer should be visible in Manipulate
pane. Every time you run this Manipulate
, the same steps should be evoked.
Can we do that in Mathematica?
Edit: For the revised question, as described it is not clear why you want a Manipulate
as opposed to using Input
.
Clear["Global`*"]
Using Slider
Panel[
x = 0;
y = 0;
result = {};
While[Not[IntegerQ[x] && 1 <= x <= 10],
(x = Input[
"What is your X value between 1 and 10?"])];
While[Not[IntegerQ[y] && 5 <= y <= 15],
(y = Input[
"What is your Y value between 5 and 15?"])];
result = x*y;
If[result === {}, "",
Manipulate[
xx*yy,
{{xx, x, "x"}, 1, 10, 1, Appearance -> "Labeled"},
{{yy, y, "y"}, 5, 15, 1, Appearance -> "Labeled"}]],
"Product of X and Y"]
Or using SetterBar
Panel[
x = 0;
y = 0;
result = {};
While[Not[IntegerQ[x] && 1 <= x <= 10], (x = Input[
"What is your X value between 1 and 10?"])];
While[Not[IntegerQ[y] && 5 <= y <= 15],
(y = Input[
"What is your Y value between 5 and 15?"])];
result = x*y;
If[result === {}, "",
Manipulate[
xx*yy,
{{xx, x, "x"}, Range[10], ControlType -> SetterBar},
{{yy, y, "y"}, Range[5, 15], ControlType -> SetterBar}]],
"Product of X and Y"]
THIS IS AN EXTENDED COMMENT RATHER THAN AN ANSWER.
Instead of a Slider
you should consider using a PopupMenu
to choose amongst alternatives.
Define a list of countries
countries = CountryData[#, "Name"] & /@
CountryData["SouthAmerica"];
Define a list of sectors (shortened here)
sectors = {
"AGF: Agriculture/hunting/fishery",
"CO12: Crude oil/mining",
"MA1: Manufacturing/petroleum refining",
"MA2: Manufacturing-other"};
Manipulate[
{country, sector},
{{country, 1, "Choose a country"},
Thread[Range[Length[countries]] -> countries], ControlType -> PopupMenu},
{{sector, 1, "Choose a sector for targeting"},
Thread[Range[Length[sectors]] -> sectors], ControlType -> PopupMenu}]
Correct answer by Bob Hanlon on September 1, 2021
Slider is best for adjust Reals. SetterBar is nice to Integer.
Like everything else a lot is a matter of taste. Some like it more individualizable.
Manipulate[
Which[typeSelected == 1, Row[{"Product of x * y = ", x*y}],
typeSelected == 2, Row[{"Product x * y = ", x*y}], True,
"No way ! Please report a bug"],
Grid[{{Style["Selection of x and y", 10], SpanFromLeft}, {"Select",
TabView[{{1,
"x" -> Row[{"x= ",
SetterBar[Dynamic[x, {x = #} &], Range[10]]}]}, {2,
"y" -> Row[{"y= ",
SetterBar[Dynamic[y, {y = #} &], Range[11] + 4],
Dynamic[y]}]}}, Dynamic[typeSelected]]}}, Frame -> All,
Spacings -> .5, FrameStyle -> Gray], {{x, 1}, None}, {{y, 1},
None}, {{typeSelected, 1}, None},
TrackedSymbols :> {x, y, typeSelected}]
Some nice too is:
{Slider2D[Dynamic[y], {{1, 5}, {10, 15}, {1, 1}},
Appearance -> "Labeled"], Dynamic[y[[1]]*y[[2]]]}
A more sophisticated example:
DynamicModule[{pt = {3, 7}}, {LocatorPane[Dynamic[pt],
Graphics[Rectangle[],
GridLines -> {{1, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10}, {5, 6, 7, 8, 9,
10, 11, 12, 13, 14}}, Frame -> True,
PlotRange -> {{1, 10}, {5, 15}}]], Dynamic[Round@pt],
Dynamic[Round@pt[[1]] Round@pt[[2]]]}]
Somehow Wolfram Inc. is working on Manipulate still. Have a look at
Answered by Steffen Jaeschke on September 1, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP