I have a formula that always evaluates to a certain number for any variable X under one condition that X is an integer and greater than 0.
So how can I evaluate Func[X] and specify that X is an integer greater than 0? is there a way to do that? I tried saying Func[Round[X]] but it didn't work, it just used Round[X] as a variable instead of understanding that it means X is an integer.
Ok I will give exactly what I'm trying to do, it's fairly simple:
$p= \begin{array}{cccccccccc} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0.5 & 0 & 0.5 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0.5 & 0 & 0 & 0 & 0.5 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0.5 & 0 & 0 & 0 & 0.5 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0.5 & 0 & 0.5 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0.5 & 0 & 0.5 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ \end{array} ;$
$\text{mainWin}=\{0,12.4461,24.8921,37.3382,49.7842,62.2303,74.6763,87.1224,99.5685,112.015\};$
$u=\{0,0,0,1,0,0,0,0,0,0\};$
Now I'm evaluating: $(u.\text{MatrixPower}[p,x]).\text{money}$ where $x$ is a positive integer
This will always evaluate to: 37.3382 which if you notice is the fourth entry in $money$ which is also the state that we started with.
Now I want to know if mathematica can figure that out (that it always evaluates to this number) if I indicate that $x$ is a positive integer. If I just use $x$ normally:
(u.MatrixPower[p, x]).mainWin // Simplify
I get:
37.3382 + (2.77553*10^-24 - 1.91762*10^-31 I) (-0.5)^
x - (1.77636*10^-15 - 1.59872*10^-14 I) (-0.116393 - 0.396276 I)^
x + (3.55271*10^-15 - 1.95399*10^-14 I) (-0.116393 + 0.396276 I)^
x + (7.10543*10^-15 - 4.73403*10^-15 I) (-2.20245*10^-16)^
x - (5.68434*10^-14 + 2.27918*10^-16 I) 0.732786^x
As you can see I just want to get rid of that imaginary part
The answers here are quite educational (I'm new to Mathematica) but unfortunately they don't give the required outcome.
Just for the interested; this is modelling the outcome of a gamble where you have p as the probability matrix, your initial state is number 4. and what I'm doing here is guaranteeing that I get one outcome no matter how many times I gamble, and that outcome is equal to whatever I started with.
This is Mathematica code:
p = \!\(\*
TagBox[
RowBox[{"(", "", GridBox[{
{"1", "0", "0", "0", "0", "0", "0", "0", "0", "0"},
{"0.5`", "0", "0.5`", "0", "0", "0", "0", "0", "0", "0"},
{"0.5`", "0", "0", "0", "0.5`", "0", "0", "0", "0", "0"},
{"0", "0.5`", "0", "0", "0", "0.5`", "0", "0", "0", "0"},
{"0", "0", "0", "0.5`", "0", "0.5`", "0", "0", "0", "0"},
{"0", "0", "0", "0", "0.5`", "0", "0.5`", "0", "0", "0"},
{"0", "0", "0", "0", "0", "0", "1", "0", "0", "0"},
{"0", "0", "0", "0", "0", "0", "0", "1", "0", "0"},
{"0", "0", "0", "0", "0", "0", "0", "0", "1", "0"},
{"0", "0", "0", "0", "0", "0", "0", "0", "0", "1"}
},
GridBoxAlignment->{
"Columns" -> {{Center}}, "ColumnsIndexed" -> {},
"Rows" -> {{Baseline}}, "RowsIndexed" -> {}, "Items" -> {},
"ItemsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.7]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {},
"ItemsIndexed" -> {}}], "", ")"}],
Function[BoxForm`e$,
MatrixForm[BoxForm`e$]]]\);
mainWin = {0, 12.4460563, 24.89211259, 37.33816889, 49.78422519,
62.23028148, 74.67633778, 87.12239407, 99.56845037, 112.0145067};
u = {0, 0, 0, 1, 0, 0, 0, 0, 0, 0};
(u.MatrixPower[p, x]).mainWin // Simplify
p-- would you please include a copy of that in Mathematica code so I don't have to waste time on it? – Mr.Wizard Apr 10 '13 at 20:36Chopto get rid of the small complex numbers. – Sjoerd C. de Vries Apr 10 '13 at 21:15