Hot answers tagged functions
24
Internal`InheritedBlock (IIB) is similar to Block, except that it preserves the original definition of the function being passed to it. The function can then be modified as we wish inside the IIB without affecting the external definition.
Let's see how Block works first:
f[x_] := x
Block[{f},
Print@DownValues[f];
f[x_, y_] := x y;
...
10
First, you can try to apply the FunctionExpand command to the DifferenceRoot object. If it is able to find a closed form of the sequence, then the Limit might be able to find an exact symbolic limit.
To find a numerical approximation, you can use the SequenceLimit command. In general, it does not guarantee to give the correct result, but if your sequence ...
10
The code for the default ComplexityFunction was posted on MathSource a number of years ago by Adam Strzebonski (of Wolfram Research). You will see reference to the original reply from Adam referenced in a MathGroup reply from Andrzej Kozlowski dated 12 Jan 2010 with the subject: "[mg106386] Re : Radicals simplify". I mention all that because I can't get the ...
9
This is perhaps a place to start:
position[expr_, level_: 1] :=
With[{positionData =
SortBy[
#[[1, 1]] -> #[[All, 2]] & /@
GatherBy[Extract[expr, #, Verbatim] -> # & /@ Position[expr, _, level], First],
Min[Length /@ #[[2]]] &
] // Dispatch},
Replace[#, positionData] &
]
The second argument controls the ...
7
Here is what I know about this. I do not know the answer to the question, but I have some guesses at an explanation. I also give some workarounds and a few simple, curious examples that illustrate some issues.
Preliminaries
First of all, Solve uses different algorithms for different types of problems, some description of which can be found in the ...
6
You can use functions with optional arguments
For example:
ClearAll@f;
Options[f] = Options[Plot];
f[p_, opt : OptionsPattern[]] := Plot[Sin[p*x], {x, 0, 2 Pi}, opt]
f[3]
f[3, PlotStyle -> {Red, Thick}, ImageSize -> Small]
For completeness sake: you can define your function to accept other options (not just those of Plot). In that case you ...
5
Perhaps the closest to what you want is to set the HoldAll attribute on the function d. This way, it won't evaluate the argument p[x,y,z] at the time it is called, so that the pattern starting with psi in your definition can be matched.
I also had to add the arguments of psi to the body of d where the derivatives are being performed:
Clear[d]
d[psi_[a_, ...
4
Temporary message: First of all, sorry for the big mess, especially the 20 line long paragraph. I am tired :)
Below, on second thought the Verbatim option is no good yet, as the rules should be gathered differently in the case we do not use Verbatim, but I guess the code does not hinder the proper implementation of this. Allow me to show you this work in ...
4
PossibleZeroQ[ #, Method -> "ExactAlgebraics"] provides the most efficient and exact test whether two algebraics are equal, (see e.g. Most efficient way to determine conclusively whether an algebraic number is zero for some benchmarks). It is Listable so we can define the following function:
ContainsAlgebraicQ[list_, a_] :=
...
4
Assumptions
I will assume that your data are contained in a nested list of {x, y} pairs such that a single dataset can be extracted via data[[i]]. We can make some example data using:
data = Transpose@Table[{x, (a + b x ) (1 + RandomReal[{-0.15, 0.15}]) /. {a ->
0.1 i, b -> i}}, {x, 0, 10, 1}, {i, 1, 10}];
Solution
I think LinearModelFit is ...
3
Not a complete answer yet:
I've built the functionality using DynamicModule and Animator, thinking that it will be possible to manually set the index i when using the second argument of Dynamic. Sadly this only works if the animation is not running. So if the animation is not running i is reset correctly. Still, here is the code
EDIT
Stealing from Kuba, I'm ...
3
This is not an answer, but some clue which I think might suggest a bug on what is going on.
First I'd like to state that the following test is done in Mathematica 9.0.1 only, and I have no idea about the cases in other versions.
The inconsistency
Now let's start a fresh kernel, evaluate one of the examples in the question:
PossibleZeroQ[Re[Root[5 + 20 ...
3
This post is a partial answer, directed at your question about your syntax, which is incorrect as posted.
In Mathematica, a function function of one variable t is defined with the syntax f[t_] := ..., not f(t) = .... Note the square brackets [ ] and the underscore _ after the the t which identifies t as a variable.
Further, I don't understand why you ...
3
Easier if you avoid radicals in the setup of the equations. This can be done by working with squares of distances.
f[x_] := x^4 - 2 m x^2 + m + 1
pts = {x, f[x]} /. Solve[f'[x] == 0, x];
pairs = Partition[pts, 2, 1, {1, -2}]
(* Out[75]= {{{0, 1 + m}, {-Sqrt[m], 1 + m - m^2}}, {{-Sqrt[m],
1 + m - m^2}, {Sqrt[m], 1 + m - m^2}}, {{Sqrt[m], 1 + m - m^2}, ...
2
I think the complexities of things like PatternTest will obstruct any kind of data structure for searching for general pattern matches. I think some regularity, either with the pattern as in Mr Wizard's answer or with the expression as in Leonid Shifrin's remark, will be needed in order to beat using Position. Jacob Akkerboom has pointed out problems with ...
2
This is a similar approach to Mr. Wizard's I suppose, but using the function's DownValues instead of a dispatch table to store the rules.
One major difference is that this code won't work with data containing pattern objects (I guess this might be fixable with Verbatim).
The expression is traversed using MapIndexed, for each part visited the position is ...
2
It is not clearly explained in your post, what should be the result. I can only guess, that you would like to get the function (the one you posted) modified by some noise.
Here the function noisedSignal[] is introduced. Check Menu/Help/tutorial/DefiningFunctions. It contains your signal modified by the noise. The latter is represented by RandomReal. Check ...
1
Yet another way to do this is to PadRight with the zero string...
ilist = PadRight["0" <> ToString@ # & /@
Sort[RandomSample[Range[1, 99999], 3], Less], 5, "0"]
(* {027082, 039217, 085143, 0, 0} *)
Head /@ ilist
(* {String, String, String, String, String} *)
1
If list has sufficiently many repeated subexpressions, it becomes efficient to convert the elements to explicit algebraic numbers in a common number field.
list=ToNumberField[list,All]
Performance testing suggests that ToNumberField memoizes evaluations of subexpressions. Evaluation is fast when the input is an algebraic combination of previously ...
1
First I've give one way that fits with the setup in your question, and then I'll give the way I would do it myself, in case that helps.
Wrap Animate in Dynamic and make it track g; also keep the Manipulate from tracking g. Wrapping Animate will make it reset whenever g is changed.
gPrev[x_] := Sin[x];
Manipulate[
Switch[functionNumb, 0, g[x_] := ...
1
I do not get the same results. If I do
ClearAll[Operator, ff, gg, x1, x2]
Operator[f_, g_, x__, opt_] :=
Piecewise[{{f[x], opt == 1}, {Operator[f, g, g[x], 1], opt == 2}}]
ff[x__] := {x[[2]], x[[1]]}
gg[x__] := {-x[[1]], -x[[2]]}
then
{Operator[ff, gg, {x1, x2}, 2],
Operator[ff, gg, gg[{x1, x2}], 1],
ff[gg[{x1, x2}]]}
-> {{-x2, -x1}, {-x2, -x1}, ...
1
I don't think this is substantially different from what @Daniel Lichtblau proposed, but it directly uses your code up to the final Solve expression, where it also uses the trick of squaring in order to avoid square-roots:
Solve[{ab^2 == bc^2, bc^2 == ac^2, ac^2 == ab^2, m > 0}, m, Reals]
(* Out: {{m -> 3^(1/3)}} *)
1
try this for the original question (without the k..)
Last@Last@
Reap[ Do[If[
And @@ Table[
f[n]/f[m] > 1 + Log[n/m]/(Log[n] Log[Log[m]]) ,
{m, 2, n - 1}] , Sow[n]] , {n, 3, 100}] ]
If you want to use explicit loops you need an outer n loop and inner m loop.
Last@Last@Reap[ Do[
m = 2;
While[m < n ...
1
There's another syntax for Blend which lets you control the color-banding easily:
cf = Blend[{
{0., Blue},
{0.1, Green},
{0.15, Black},
{0.2, Red},
{0.8, Purple},
{0.95, Cyan}
}, #1] &
DensityPlot[Sin[a] Sin[b],
{a, -2 Pi, 2 Pi},
{b, -2 Pi, 2 Pi},
PlotPoints -> 250,
ColorFunction -> cf ,
...
Only top voted, non community-wiki answers of a minimum length are eligible


