# Tag Info

11

tbl = RandomInteger[{0, 3}, {10, 2}] (* {{0, 3}, {0, 0}, {1, 3}, {2, 0}, {2, 0}, {0, 0}, {1, 1}, {2, 2}, {1, 0}, {3, 3}}*) You have many alternative methods: Cases[tbl, {x_, 0} :> x] (* or *) Cases[tbl, {_, 0}][[All, 1]] (* or *) DeleteCases[tbl, {_, Except[0]}][[All, 1]] (* or *) Select[tbl, Last[#] == 0 &][[All, 1]] (* or *) ...

8

You mean something like this? SetDirectory[NotebookDirectory[]]; m = Import["f.txt", "Table"]; getColor[m_List, i_Integer] := Module[{lim1 = 0.0001, f = m[[i, 6]], s = m[[i, 7]]}, Which[ f > lim1 && s == 0, Orange, f <= lim1 && s == 0, Red, f > lim1 && (s == 1 || s == 2), Green, f <= lim1 && (s ...

6

One can use x-Floor[x] instead of FractionalPart[x] for positive x FullSimplify[Cos[2 Pi ((i + j + k)/2 - Floor[(i + j + k)/2])], Assumptions -> (i | j | k) ∈ Integers] (-1)^(i + j + k)

6

This answer intends to answer both parts of the question. Originally it answered only the first part. Below is the original answer. Scroll down for the second part. I interchanged the third and second argument of ForAll and gave the function IsSuppFun attribute HoldAll, and it worked! So I wrote SetAttributes[IsSuppFun, HoldAll] IsSuppFun[f_[t_]] := ...

6

Yes, it is possible. However, it requires the use of the undocumented SystemPrivate\$Localized, which was (as far as I know) first discovered by @Rojo. This symbol is most likely an internal implementation detail of the evaluator and, being located in a context that is obviously not meant for manipulation by the user, should be approached with caution. It ...

6

Something like Pick @@ Transpose@largetable~Join~{0} might do it. Unless 0 should be the Real number 0. If you have both, then try Pick @@ Transpose@largetable~Join~{0 | 0.} Edit: The above is the same as Apply[Pick, Join[Transpose[largetable], {0 | 0.}]] and has the same effect as With[{columns = Transpose[largetable]}, Pick[columns[[1]], ...

5

Different approach: list = Import["nb.txt", "Table"] lim = .0001; c1 = # > lim && #2 == 0 &; c2 = # <= lim && #2 == 0 &; c3 = # > lim && (MemberQ[{1, 2}, #2]) &; c4 = # <= lim && (MemberQ[{1, 2}, #2]) &; An array with indicators if given record fulfills given condition: cond = Outer[Apply, {c1, ...

5

A great resource about such stuff is the Tutorial: Package Design. Luckily, it was written by Todd Gayley who is also a registered member of Mathematica.SE. The important part can be found in section Error Handling If a more complex test of the input is required, you can put the Condition as the last statement in a Module: f[x_List] := ...

5

Your posted code does not work because some of the code you want to evaluate is given as an argument to Condition which holds its arguments, you could make it work by changing this f[x_] := Block[{ans, success}, ans = If[x >= 0, success = 1; Sqrt[x], success = 0]; ans /; (success == 1) ] Notice that the first line of code is process outside ...

5

A combination of Module and Condition acts very much like the proposed Block / If pseudo-code: mySet[x___] := Module[{n = DeleteDuplicates @ {x}} , mySet @@ n /; Length @ n =!= Length @ {x} ] mySet[a, b, c] (* mySet[a, b, c] *) mySet[a, a, a, b, b, b, c, c] (* mySet[a, b, c] *) We compare the lengths of the original and final lists in order to ...

5

What you have is basically a nonlinear second order recursion, and in this case it can be solved by: sol = RSolve[-k x f[x] + k (x + 1) f[x + 1] - r f[x] + r f[x - 1] == 0, f[x], x] The answer is fairly large, and besides having variables r and k, it also has two constants C[1] and C[2], so there may be enough flexibility to enforce your desired ...

5

As a work-around : Expectation[x \[Conditioned] x > 30, x \[Distributed] MarginalDistribution[speedDistr, 2]] (* 34.8138 *)

4

Just for illustrative purposes. You can modify and limit range in parameter space as required. Manipulate[ {p, q} = m; p1 = ParametricPlot[fun[x, y], {x, 0, 1}, {y, 0, 1}, Epilog -> {{Red, PointSize[0.02], Point[fun[p, q]]}, Text[fun[p, q], {3, 5}]}, PerformanceGoal -> "Quality", ImageSize -> {300, 300}]; p2 = ParametricPlot[fun[x, ...

4

Here is a solution : acceptableQ[k_, y_, z_] := Not[Or[ k == 1 && y == "low" && z == "b", k == 1 && y == "high" && z == "b", k == 1 && y == "medium" && z == "a", k == 1 && y == "high" && z == "a", k >= 2 && y == "high" && z == "b", ...

4

Table works much like Do -- you can have any number of statements inside. For instance: Table[r = 100; statement1; statement2; RandomReal[{-1, 1}], {i, 1, 10}] Here the r = 100 doesn't do anything, and the statements can be anything -- just separate them with a semicolon. The final term (in this case a RandomReal) occurs without semicolon and is the thing ...

4

Using the 4th argument of If should do the trick F[x_] := If[x >= 0, Sqrt[x], Defer[F[x]], Defer[F[x]]] {F[2], F[-2],F[a]} (* {Sqrt[2],F[-2],F[a]} *) or may be F[x_] := If[x >= 0, Sqrt[x], HoldForm[F[x]], HoldForm[F[x]]] so that F[a]/. a-> 2//ReleaseHold (* Sqrt[2] *) The first form (using Defer) would work also with F[a]/. ...

4

You may be able to get what you want by setting a Hold attribute on your function: SetAttributes[IsSuppFun, HoldAll] IsSuppFun[f_[t_]] := Resolve[ForAll[t, 0 <= t <= 2 && t \[Element] Reals, f[t] + D[f[t], {t, 2}] >= 0]] f[t_] := t^2 - 3 IsSuppFun[f[t]] False

4

Numerical integration in Mma is a big topic. I suggest reading at least this. The following gives the correct answer: NExpectation[(-(x*y) + z^2) Boole[x*y - z^2 <= 0], {x, z, y} \[Distributed] MultinormalDistribution[{0, 0, 0}, {{3/8, 0, 1/8}, {0, 1/8, 0}, {1/8, 0, 3/8}}], Method -> {"NIntegrate", {Exclusions -> True}}]

4

If you are not concerned by the particular color order or choice, as your conditions partition your data you could use GatherBy[]. Let your data be in variable data. You could use: gather=GatherBy[data,{#[[-2]]<=0.0001,#[[-1]]==0}&]; ListPlot[#[[All,{1,2}]]&/@gather,PlotStyle->{Orange,Red,Green,Blue}] The gather will partition your data into ...

4

Assuming you have version 9 you can do the following. data = {{-1, 0}, {0, 0}, {1, 0}, {-2, 1}, {2, 1}, {-1, 3}, {1, 3}}; dist = EmpiricalDistribution[data]; Table[Expectation[y \[Conditioned] x == i, {x, y} \[Distributed] dist], {i, -2, 2}] (*{1, 3/2, 0, 3/2, 1}*) Note: Conditional probabilities and expectations didn't work for EmpiricalDistribution ...

3

Here's my approach: The data is already quantized on a 1/100 grid so I believe we should be plotting it as such. First Import the data and extract the columns we wish to work with: data = Import["data_gRC.out", "Table"][[All, {1, 2, 6, 7}]]; Check the ranges of the coordinates: minmax = {Min@#, Max@#} & /@ Take[Transpose[data], 2] {{-0.54, 0.54}, ...

2

A general approach is to use the function Piecewise. You might define your function: pv[x_] = Piecewise[{{0, x == 11}}, -5/1.05^x] which says that if the input is 11, make the output 0, otherwise make it -5/1.05^x. You can call this with your stoptime pv/@stoptime which gives the answer you expect. Another way to do this is to define the function ...

2

Note that Power and Times have the attribute Listable, you can thus e.g. do: x^# &[Range[10]] or (the same) Power[x, Range[10]] to get: {x, x^2, x^3, x^4, x^5, x^6, x^7, x^8, x^9, x^10} Thus, you can apply your function pvccosts on stoptime directly. In my suggestion (in the comments): pvcosts = If[# == 11, 0, (-5/1.05^#)] & /@ ...

2

At my machine HP, Mma 9.0.1.0, WinXP Timing[Integrate[1/Sqrt[z - Cos[x]], {x, 0, 2*Pi}, Assumptions -> z > 1]] (* {1.187500, ( 2 (Sqrt[1 + z] EllipticK[-(2/(-1 + z))] + Sqrt[-1 + z] EllipticK[2/(1 + z)]))/Sqrt[-1 + z^2]} *) 1.9 seconds is not too much, is it? Might it be that you had some expensive process on the background? Otherwise ...

2

Using the solution proposed in this answer also works: FullSimplify[Cos[2 Pi FractionalPart[1/2 (i + j + k)]], Assumptions -> {Element[i + j + k, Integers], i > 0, j > 0, k > 0}, ComplexityFunction -> LeafCount] Giving: (-1)^(i + j + k)

2

I should perhaps make this post a comment and not an answer. However, I wish to fully support the comments of @AndyRoss (and have +1 his answer). cas = Cases[list, {#, y_} :> y] & /@ Range[-2, 2]; ans = {Mean[#], Mean[(# - Mean[#])^2]} & /@ cas; Style[Prepend[ MapThread[Prepend[#1, #2] &, {ans, Range[-2, 2]}], {"x", "E[Y|X=x]", ...

2

@Daniel Lichtblau's comment seems like an answer that is worth putting in an answer: (1) Integrate will not catch conditions that are discrete. (2) As was pointed out already in comments, the result is correct anyway; the singularity is removable (e.g. via Limit). Edit: I might add that GenerateConditions might yield a ConditionalExpression but not a ...

2

Based on your self-answer I think you want this: SeedRandom[0] FullTab1 = RandomComplex[{0 I + 0, 2 I + 2}, {20, 3}]; (* example data *) sel = Select[FullTab1, Im[First[#]] > 0.9 &]; lgt = Length @ sel; {ext, mx1, mx2} = Transpose[{Re@sel, Im@sel}, {3, 2, 1}]; ListPlot[ext] ListPlot[mx1] ListPlot[mx2]

1

For example, here is a way to do what you want with one single function. In the following example, instead of Null, the "forbiden" value is 1, and someactionis computing Mod[x, 2] function (which gives the remainder on division of x by 2). Let's define someaction, Mathematica allows to do this : someaction[x_List] := someaction /@ DeleteCases[x, 1]; ...

1

You don't have to re-evaluate the integral with assumptions. You can instead use Simplify with assumptions directly on the conditional expression. In your second example Integrate[ 1/Sqrt[ x^2 + y^2 - 2 x y Cos[z]], {z, 0, 2π}] the output is ConditionalExpression[(2 EllipticK[(-4 x y)/(x - y)^2])/Sqrt[(x - y)^2] +(2 EllipticK[(4 x ...

Only top voted, non community-wiki answers of a minimum length are eligible