# Tag Info

16

There was an update for Array, not done to the end. The method below does not work for earlier versions even though that Array is New in 1 | Last modified in 4 Moreover WRI forgot to update docs for error messages: Array::plen - the first example gives no error in V9. V9 Array[# &, n, {start, stop}] Array[# &, 10, {-1, 1}] {-1, ...

12

There are nice trigonometric formulas δ = 0.01; trg[x_] := 1 - 2 ArcCos[(1 - δ) Sin[2 π x]]/π; sqr[x_] := 2 ArcTan[Sin[2 π x]/δ]/π; swt[x_] := (1 + trg[(2 x - 1)/4] sqr[x/2])/2; Plot[{TriangleWave[x], trg[x]}, {x, -2, 2}, PlotRange -> All] Plot[{SquareWave[x], sqr[x]}, {x, -2, 2}, PlotRange -> All, Exclusions -> None] Plot[{SawtoothWave[x], ...

8

How about writing the Gram-Schmit down by yourself? GramSchmidt[w_?MatrixQ] := Module[{v = ConstantArray[0, Length[w]]}, Table[ v[[n]] = w[[n]] - Sum[(v[[i]].w[[n]]/v[[i]].v[[i]])*v[[i]], {i, 1, n - 1}], {n, 1, Length[w]}]; v ] Then you have the unscaled orthogonal basis GramSchmidt[{{1, 1, 1}, {1, 1/2, 1/3}, {1, 2, 3}}] ...

8

I'd go with the BinLists method. Were that not available, one could do well with a zero-order interpolation. These can be useful if the fence list is large, because lookup is efficient (log(n) rather than n). I do some negating to get the continuity to be at the left end of the intervals. interp[x_List] := With[{newx = Join[{-10^8}, x, {10^8}]}, ...

8

You can specify the evaluation of which construct should be stopped by Return by providing the second argument (undocumented?). For example, Scan[Function[x, Module[{}, Print[x]; Return[$Failed, Module]; Print[-x]]], {1, 2, 3}] or Scan[Function[x, Print[x]; Return[$Failed, CompoundExpression]; Print[-x]], {1, 2, 3}]

7

It's hard to reply without larger context, but if you are not restricted to use pure functions, then one option would be to use the pattern-defined overloaded function instead: ClearAll[fun]; fun[2] := Null; fun[x_] := ((*Do something useful*)Print[x]) Then, you just write: Scan[Function[x, Scan[fun, x]], {{1, 2, 3}, {4, 5, 6}}] In fact, you can as ...

7

As belisarius has shown(and I have voted for his answer) RegionPlot3D allows you to plot your region. FYI: Your lists of coordinates (as with all lists in Mathematica): coord = {{1, 0, 1}, {2, 0, 1}, {1, 0, 2}, {2, 0, 2}, {1, Pi/6, 1}, {2, Pi/6, 1}, {1, Pi/6, 2}, {2, Pi/6, 2}}; You can transform these cylindrical coordinates to cartesian coordinates: ...

7

I can see the source of your confusion: If you use Head[f[x]] and Head[5] you get f and Integer respectively. Then, you read the documentation Apply[f,expr] or f@@expr replaces the head of expr by f. and you expect Cos@@5 to replace the Integer head by Cos. The way I explain it to myself is by saying Mathematica has two (types of) heads ;-) One type is ...

7

One approach is to convolve the sawtooth wave directly with a Gaussian kernel. Since this can be done analytically, it is possible to return a function that is in closed form and hence can be differentiated without interpolation. f = Integrate[SawtoothWave[t/10] Exp[-3 (t - x)^2] , {t, 0, 50}] Plot[f, {x, 0, 50}] You can control the amount of "rounding" ...

7

The possibility to insert operators and functions as you know them from mathematics is not possible for all things. Usually, you find the special input possibilities on the reference page of the function in the Details section. See for instance the documentation of Integrate. For Binomial there seems to be no such 2d input, because as you already found out, ...

6

I like to think about @@ as a Frankstein decapitation operator. It take out the Head of the old expression and replace by the new one. And @@@ as a mass Frankstein decapitation operator. It get inside each list element and apply @@ to each element inside the list. To understand what Head means, use FullForm. For example, in the list l={1,2,3} if you apply ...

6

You could integrate over the region, using Boole: Integrate[ Boole[0 < p < 1 && 0 < e1 < 1/2 && 0 < e2 < 1/2 && (p < e1 || (p) (e1)/((p) (e1) + (1 - p) (1 - e2)) < e1/e2)], {p, 0, 1}, {e1, 0, 1/2}, {e2, 0, 1/2}] (* 1/16 (5 - 6 Log[2] + 2 Log[4]) *)

6

I have found this solution: In[1]:= f[x_] := CellPrint[{ Cell[BoxData[ToBoxes[x + 1]], "Output"], Cell[BoxData[ToBoxes[x + 2]], "Output"]}] In[2]:= f[2] 3 4 I was originally trying to achieve something like this: f[data_] := CellPrint[{ Cell["Data", "Subsection"], ...

5

Just to get you started RegionPlot3D[ 0 < z < 1 && 1 < Norm[{x, y}] < 2 && 1/2 < ArcTan[y, x] < 1.1, {x, 0, 3}, {y, 0, 3}, {z, -1, 2}, PlotPoints -> 100, Mesh -> False, PlotStyle -> Directive[Opacity[.3], Yellow]]

5

Here's something I use in class to demonstrate cylindrical coordinates (sorry for the length, but it's what I have :): Manipulate[ With[{$θColor = Red,$rColor = Darker[Blue], $zColor = Brown}, figure[P0_, 0., 0., 0.] := { Thick,$rColor, Line[{{0, 0, 0}, {P0[[1]], P0[[2]], 0}}], $zColor, Line[{{P0[[1]], P0[[2]], 0}, P0}] }; figure[P0_, ... 5 One part of your question is about iteration. Building on Yves comment, one good way is to pack everything inside a function. To simplify your problem, say the function is: f := RandomReal[{0, 1}]; Each time f is called, you get a new random number. (This greatly simplifies your problem, but the same idea holds.) Now to iterate 1000 times, you can use Map ... 5 Actually, your two results only differ by a constant of$\pm\sqrt2$. This is perfectly OK as you are dealing with indefinite integration. Try: Integrate[1/(r^2 Sqrt[x/r^(4 - 2 \[Gamma]) + 1]), r]; a = FullSimplify[% /. {x -> 2, \[Gamma] -> 3}] b = Integrate[1/(r^2 Sqrt[2/r^(4 - 6) + 1]), r] Assuming[r \[Element] Reals, FullSimplify[a - b]] 5 You can try this! fences = {1, 5, 9, 14}; vals = {-1, 1, 3, 4, 6, 9, 10, 13, 14, 15}; Select[vals, #] & /@ (Function[{x}, #1 <= x < #2] & @@@Partition[fences, 2, 1, {2, 1}, {Infinity, -Infinity}]) {{-1}, {1, 3, 4}, {6}, {9, 10, 13}, {14, 15}} 5 This is probably not going to be the best answer but offering it as an opener or as a guide to towards a better solution Setting your initial input as a function f[n_]:=Length[Select[IntegerPartitions[10],First[#]==n&]] then Map[f,Range[10]] {1, 5, 8, 9, 7, 5, 3, 2, 1, 1} No doubt regular contributors can improve on this 4 Here's another way using SplitBy fences = {1, 5, 9, 14}; values = {-1, 1, 3, 4, 6, 9, 10, 13, 14, 15}; Then: SplitBy[values, Function[{z}, #1 <= z < #2] & @@@ Partition[fences, 2, 1]] // Flatten[#, Length[fences] - 2] & Which gives: {{-1}, {1, 3, 4}, {6}, {9, 10, 13}, {14, 15}} 4 Assuming there is a Method other than "AllTours" that doesn't break if one point doesn't obey the triangle inequality, introduce a special point that has a distance 0 to all other points: points = {{-0.9, -0.89}, {.99, .97}, {0.1, .0}, magicPoint}; d[args__] /; FreeQ[{args}, magicPoint] := EuclideanDistance[args] d[__] = 0; FindShortestTour[points, ... 4 You could use table... unless I am missing something really basic. Speed, maybe? Edited to consider the special case as suggested by Kuba. linspace[start_, stop_, n_:100] := Table[x, {x, start, stop, (stop - start)/(n - 1)}] linspace[start_, stop_, 1] := Mean[{start,stop}] 4 The only method I can think of that will use the built-in simplification routines is to snoop on transformations using either TransformationFunctions or ComplexityFunction. Unfortunately neither of these will be restricted to the entire expression therefore what is produced may not be usable. Nevertheless as an example: FullSimplify[Gamma[1 - x] Gamma[x] ... 4 Maybe TimeConstraint is helpful: y = Gamma[1 - x] Gamma[x] Sin[Pi x] + Gamma[x] Gamma[1 - x] Sin[Pi (1 - x)]; FullSimplify[y, TimeConstraint -> 0.000001] FullSimplify[y, TimeConstraint -> 0.0001] FullSimplify[y, TimeConstraint -> 0.01] Gamma[1 - x] Gamma[x] Sin[π (1 - x)] + Gamma[1 - x] Gamma[x] Sin[π x] 2 Gamma[1 - x] Gamma[x] Sin[π x] 2 π 3 EDIT My previous answer related to the title of the question and was directed to "reaping" or "catching" first cases of a condition being met from a loop. The Euler formula, as I now understand, was a method for generating consecutive prime numbers :$n^2+n+k$, where$k$is prime and$n$ranges from 0 to$k-2\$. With all due respect this does not appear ...

3

You use #[[i]]&/@somelist a lot when instead you can use a part specification like: somelist[[All, i]] to get the i-th column. To count miss-classified you can look at the difference of the lists and count all non-zero elements like: Length[Select[Table[sig[[i]] != datasig[[i]], {i, 100}], # == True &]] (* Same as: *) Total@Unitize[sig - datasig] ...

3

I usually set up a wrapper function that transforms if input is valid and otherwise acts like Identity: pickyTransform[expr_] := 0 helper[expr_] /; ! AtomQ[expr] && FreeQ[expr, _?NumericQ] := pickyTransform[expr] helper[expr_] := expr FullSimplify[a^3 + x^y, TransformationFunctions -> {helper}] (* a^3 *) This works fine most of the time, but ...

3

You do not have to define a function to plot it. You can certainly do a=1; f:=a+x; Plot[f,{x,0,10}] and the output is the graph you expected. Defining the function as above has many drawbacks: 1) You cannot evaluate it without making an explicit replacement. For example, f(2) becomes f/.x->2 I would generalize this point and say that defining ...

3

There are as usual several ways. The most convenient one is probably MemberQ, as already pointed out in the comments. MemberQ[{1, 2, 3, 4, 9}, 9] (* True *) If you have a complex structure and not only a flat list, then FreeQ can be of use. Note that you have to negate the result. MemberQ[{1, 2, {3}, {{4, 9}}}, 9] Not[FreeQ[{1, 2, {3}, {{4, 9}}}, 9]] (* ...

3

Your equations don't seem to be consistent. y = E^-9.25 0.0000961117 c = 10.^-14 - y -0.0000961117 x = c y/5.7 10.^10 -16.2061 z = 276/x^2 1.05088 a = (x + c)/2 - z -9.15396 b = x + y - 2 z - a -9.15377 However, a b /z 79.7359 while your remaining equation states 9.8x10^-13 = [(b)(a)]/(z)

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