# Tag Info

12

The answers of the original questions by Szabolcs: What does Rescale do when infinities are present? What's the justification for this behaviour? Where is it documented? were guessed correctly with the answer: If I may be allowed to speculate, these were picked because they do the job advertised and are "conveniently" algebraic. They certainly work ...

11

Agree with other answers, this is a bad idea (why, precisely do you want to do this?), but in the spirit of encouraging unmaintainable write-once read-never code, here's my entry into the freak show: \$NewSymbol = If[StringMatchQ[#, "f" ~~ NumberString], ToExpression[# <> "[x_]=x+" <> StringDrop[#, 1]]] &; Remove["f*"]; ...

9

Just to be clear, I think this is a terrible idea but nevertheless, a question has been posed for which there is a simple answer: ClearAll@fn SetAttributes[fn, HoldAll] fn[h_[x_]] /; StringMatchQ[SymbolName@h, "f" ~~ DigitCharacter ..] := First@StringCases[SymbolName@h, "f" ~~ d : DigitCharacter .. :> x + ToExpression@d] ...

6

ciao's method is good. Pick[list1, Thread[Less[list1, list2]]] {2.4, 3.4, 5.9, 1.2} Another -- perhaps more direct -- way to do it is MapThread[If[#1 <= #2, #1, Nothing] &, {list1, list2}] {2.4, 3.4, 5.9, 1.2}

6

I'm just going to walk through all of it. If something is too pedantic, skip it. Module[{f,g}... creates a scoping construct so the definitions of f and g are local to this code. Tally[a] produces a list of all the elements in a and a count for each element. For instance, Tally[{a,a,b,c,a,d,d}] would give {{a,3},{b,1},{c,1},{d,2}}. The strange ...

6

FindFormuala is EXPERIMENTAL and new in v10.2 Clear[x, y]; xData = {1, 3, 5, 11}; yData = {1, 9, 25, 121}; y[x_] = FindFormula[Transpose[{xData, yData}], x] (* x^2 *)

5

Note that neither Sign nor Abs is differentiable so that Newton's Method may not be applied to the OP's problem in its given form. Caveat: I am assuming this is a toy example, to show that the unadorned Newton's method fails on some functions. Normally, FindRoot uses step control to try to avoid certain common traps in using Newton's Method. One can turn ...

4

We can see from this expression Reap[Sow[1, #] & /@ {1, 1, 2, 3}, _, f] (* Out: {{1, 1, 1, 1}, {f[1, {1, 1}], f[2, {1}], f[3, {1}]}} *) how Sow and Reap interact in general. In this example f is {#, Tr@#2} &. Tr in this context works just like Total but it can be faster. But the sum of the second part is just the sum of 1s, the number of times ...

4

Try the following: data = Transpose[{x, y}]; FindFormula[data, z]

4

Try this: DensityTop = Table[With[{j = j, lnorm = chordlength[[1]]/chordlength[[j]]}, (.2 + 36.*^-6 chordlength[[1]]^2 - 0.012 chordlength[[1]] (# lnorm) + (# lnorm)^2 ) &], {j, 1, 25, 1}]; Note this is a different result from the other answer, which should illustrate the ...

3

In the interest of illustrating why what you've requested might be a bad idea, here's the simplest way I can think of to achieve your goal (there may be a better way): Do[(ToExpression["f" <> ToString[#]][x_] := x + #) &@ic, {ic, 1, 5}] ?f1 ?f5 It's much messier than the two characters you'd like to save and harder to index programatically, so ...

3

You can use the third argument of Solve to eliminate variables from the system $$y=f(x),\quad dy=f'(x)$$ f[x_] := 1/(1 + Exp[-x]); sol = Solve[{y == f[x], dy == f'[x]}, {dy}, {x}, Method -> Reduce] (* {{dy -> y - y^2}} *) (Or you could use Reduce directly, for the answer in a different form.) If you want an ODE, then massage sol: sol[[1, 1]] /. ...

2

Combining Michael E2's answer to another question, that redefines XMLElement, and MarcoB's answer above, here is another approach. To get the Wolfram expression of the messy XML that will recreate the original Wolfram expression (there is probably a better way): ImportString[ExportString[Hold[Times[a, Rational[1, -2], "test"]], "XML"], "XML"] This ...

2

It is because a transformation rule in the SimplifyDump context is written without taking into account that Mathematica currently doesn't simplify zeroed Quantitiy expressions to a plain zero, which prevents the rule from detecting a division by zero. This happens even in the case where the Quantity has a correct unit, such as radians. Other than these ...

2

This is an answer generated from the comments. D. Lichtblau: Introduced in either version 3 or 4, I forget which. Not sure if it has changed since then. Mr.Wizard: Since this is a longstanding feature is there a reason it has not been documented? D. Lichtblau: It is not really the most carefully designed of features. (Or so claims the ...

1

You can get the desired look using the Notation Package. << Notation` Notation[ParsedBoxWrapper[RowBox[{"f", " ", RowBox[{"n_", "[", "x_", "]"}]}]] \[DoubleLongRightArrow] ParsedBoxWrapper[RowBox[{RowBox[{"f", "[", "n_", "]"}], "[", "x_", "]"}]]] which is displayed as when the Notation Palette is used to create the second part of the above ...

1

As others have said, this is a bad idea. However, if you only care about the appearance of f, then you could so something like this: f // ClearAll; intF = RowBox[ { RowBox[ { "f", "[", #1, "]" } ], "[", #2, "]" } ] &; dspF = RowBox[ { "f", #1, "[", #2, "]" } ] &; f /: MakeBoxes[ f[ n_ ][ x_ ], form_ ] := With[ { ns = ToString @ n, xs = ToString ...

1

The answer in the link you supplied indicates that the use of the Sow and Reap approach performs better than Tally when strings are involved. However, to count the number of occurrences in your list of 3D points, Tally is actually better. list = Partition[RandomInteger[15000, 300000], 3]; Tally@list // Timing // First 0.078 seconds on my machine while ...

1

Are you new to Mathematica? To produce plots similar to those in the paper requires some trick (and cheat): a = 1; A = -3; c = 0.2; B = 1; plotpoints = 50; epsilon = 10^-5; term1num = (x^2 + y^2); term1den = (a - A*((y^2*(3*x^2 - y^2))/(x^2 + y^2)^3)^B)^2; term1 = term1num/term1den; term2[z_] := (1 + epsilon - (z^2/c^2)); term3[z_] := z^2/c^2; sort[points_] ...

1

You cand use VertexReplace to replace each vertex with its coordinates or any other values. g = GridGraph[{2, 3}, VertexLabels -> "Name"]; VertexReplace[g, Thread[VertexList[g] -> GraphEmbedding[g]]]

1

Somewhat more detailed answer, though this question "arises due to a simple mistake..." Mean takes a list as its argument. What you had was {{a, b, c}, {d, e, f}}. The FullForm of this is: List[List[a, b, c], List[d, e, f]] Apply at level 1 replaces the heads of list at level 1 like so: List[Mean[a, b, c], Mean[d, e, f]] while what you needed, was: ...

1

Looking at the features in How Player Pro Compares for EnterpriseCDF. In the Input/Output section the "Keyboard entry" lines are basically saying that there is limited functionality when entering text to be interpreted as Wolfram Language. I believe this is to prevent the creation of basically a complete interactive version of Mathematica through a CDF that ...

1

f := 1/(1 + Exp[-x]) solx = First[x /. Solve[f == g, x] /. C[1] -> 0] (* Out[233]= Log[-(g/(-1 + g))] *) Some derivatives (D[f, x] /. x -> solx // Simplify) /. g -> "f[x]" (* Out[244]= -(-1 + "f[x]") "f[x]" *) (D[f, {x, 2}] /. x -> solx // Simplify) /. g -> "f[x]" // Expand (* Out[247]= "f[x]" - 3 ("f[x]")^2 + 2 ("f[x]")^3 *) (D[f, ...

1

One way might be to solve the defining equation for the exponential function fx = 1/(1-Exp[-x]) sol = First@Solve[ f==fx/. Exp[-x]-> ex, ex] which will yield {ex -> (1 - f)/f} Put that into the differentiated function and simplify the result Simplify[ D[fx, x] /. Exp[-x] -> ex /. sol] which results in -(-1 + f) f

1

This handling of If is more or less correct behavior. The condition evaluates to True so If exits with its second argument as the result. That second arg is Return[{"Exit Block", i}, If]. At this point the evaluator figures out there is no surrounding If from which the Return can actually return, and it (apparently) bubbles up to the top level. At worst this ...

1

Partition[Table[Plot[{ DensityTop[[j]][x], DensityBtm[[j]][x]}, {x, h /. Solve[DensityTop[[1]][0] == DensityTop[[j]][h], h][[1]], h /. Solve[DensityTop[[1]][chordlength[[1]]/10^2] == DensityTop[[j]][h], h][[-1]]}, Filling -> Axis, PlotStyle -> {Gray, Orange}, PlotLabel -> j, Frame -> True, PlotRange -> ...

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