# Tag Info

5

Instead of doing the integration yourself, why not have Mathematica do it for you? g = 6.674*^-11; dt = 0.001; tStop = 2000; soln = First@NDSolve[{ x1''[t] == g (m2/Norm[x2[t] - x1[t]]^3 (x2[t] - x1[t]) + m3/Norm[x3[t] - x1[t]]^3 (x3[t] - x1[t])), x2''[t] == g (m3/Norm[x3[t] - x2[t]]^3 (x3[t] - x2[t]) + m1/Norm[x1[t] ...

2

expandNCM[(h : NonCommutativeMultiply)[a___, b_Plus, c___]] := Distribute[h[a, b, c], Plus, h, Plus, ExpandNCM[h[##]] &] expandNCM[(h : NonCommutativeMultiply)[a___, b_Times, c___]] := Most[b] ExpandNCM[h[a, Last[b], c]] expandNCM[a_] := ExpandAll[a] To eliminate ** operators: compressNCM[expr_] := expr /. NonCommutativeMultiply[x__] :> ...

7

Limitations apply, as Jens stated in a comment above. Still, if you know a form you are searching for, and can formulate a fitness function for it, you can do something like: With[ {val = 10 + 4 Sqrt[5], eq = a + GoldenRatio^b}, eq /. Last@Minimize[ {a + b, a >= 0 && b > 0 && val == eq}, {a, b}, Integers]] 1 + ...

5

To illustrate whats going on, your function is 0 at x=0, rises to a max and becomes essentially zero very quickly. With[{a = .9}, Plot[x Exp[-(a^2+.001^2) x^2], {x, 0, 3}]] Now look at the values NIntegrate computes: res = Reap[With[{a = .9}, NIntegrate[y = x Exp[-(a^2 + 0.001^2) x^2], {x, 0, 8000}, EvaluationMonitor :> Sow[{x, ...

7

I think the problem might be related to a bug in FullForm when applied to a ByteArray object: ByteArray["aV+jpGtfd3BHhoSvOthJpQ=="] // FullForm (* List[105,95,163,164,107,95,119,112,71,134,132,175,58,216,73,165] *) The full form has lost information regarding the structure of the ByteArray. The box-form of the button is using this list form but the ...

3

Treat the maximum machine number as a singularity: ListPlot[Table[{a, NIntegrate[x Exp[-(a^2 + 0.001^2) x^2], {x, 0, 0.5 Log[$MaxMachineNumber/(a^2 + 0.001^2)], 8000}]}, {a, 0.001, 1, 1/100}], Joined -> True Update [Forgive me, I actually have a job, and, while I could solve the problem quickly over breakfast, I could not compose a complete ... 6 OK, now I have another suggestion: With[{x = ToString[encryptedObj, InputForm]}, Print[x]; Button["Try with", foo = Decrypt["pass", ToExpression[x]]]] The button generates no error and foo is set to "TestCase". 2 With N replaced by n and exact numbers, the function in the Question can be written as f[n_] = Sum[Binomial[n/2 - 1, a]*Binomial[n/2 - 1, a - 1]*(7/20)*(3/10)^(n - a - 1), {a, 2, n, 2}] Although Mathematica can perform the Sum, the result in terms of HypergeometricPFQ is not particularly enlightening. Instead, plot f[n]. ListLogPlot[Table[f[n], {n, ... 6 Cleaning up your syntax (which involves a non-localized varable F and an unnecessary Return) the second case coud be written like this: test[func_] := Module[ {expression, f}, expression = Derivative[0, 1][f][x, y]; f = Function[{x, y}, #] &[func]; expression] Then the expected result comes out: test[y - x^2 + 1] (* ==> 1 *) What I did ... 2 Plot is not really for discrete results like this, though one can harangue it into doing so. Better to use DiscretePlot or ListPlot, e.g.: Table[CountingFcn[SampleDats[[j, All]], r], {j, 1, Length[SampleDats]}, {r, 0, 13}]; ListPlot[%, Joined -> True, InterpolationOrder -> 0, DataRange -> {0, 13}] 4 I might be missing the point of the question but I think you just need _?NumericQ: ClearAll[CountingFcn] CountingFcn[dat_, r_?NumericQ] := Count[dat, u_ /; u < r]; This prevents the evaluation of the function until r is numeric. Now: PlotCountsEval[SampleDats, {0, 13}] Reference: PatternTest, NumericQ 0 Malte Lenz is correct; there are no level one expressions in l therefore the Map operation appears inert. (The default levelspec of Map is {1}.) Observe that if a levelspec of {0} is used the func is applied: Map[func, l, {0}] func[l] If you are asking why conceptually Map works this way I can only say that in my experience the existing behavior has ... 0 In 10.1.0 we have the new function KeyValueMap. You can use these functions, although they are not perfect heldNormal[assoc_] := Apply[Rule, Hold@Evaluate@KeyValueMap[Hold, assoc], {2}] map[f_, assoc_] := Association @@ Unevaluated @@@ List@MapAt[f, heldNormal@assoc, {All, All, 2}] associationMap[f_, assoc_] := Association[ReleaseHold@Map[f, ... 1 You can't do this that way, when you evaluate RunScheduledTask you are only sending a held procedure for scheduled evaluation to Kernel. But Reap[expr]: gives the value of expr together with all expressions to which Sow has been applied during its evaluation. RunScheduledTask is of course HoldFirst so Sow is not applied at this time. You can put ... 1 This is not a complete answer, but it is too long to post in a comment. I have made some modifications in your code, but due to insufficient information given, I cannot completely correct it (I don't know economics). I will put the code here and possibly make other's work easier. boptval[stock_, time_, vol_, int_, expn_, payoff_, strike_, nas_] := ... 5 Sequence is treated a bit specially. It does not get "evaluated to a result", but instead as the documentation explains: Sequence objects will automatically be flattened out in all functions except those with attribute SequenceHold or HoldAllComplete. This means that even though If has attribute HoldRest, the expression If[1 == 0, x, Sequence[]] will ... 3 Sequence has non-standard evaluation rules. You can work around them like so. seq := Sequence {a, b, If[False, x, seq[]], c} {a, b, c} {a, b, If[True, x, seq[]], c} {a, b, x, c} Updated to conform with the observation made by Szabolcs in his comment below. 2 I'm guessing you are looking for the list of replacements that need to be made going down to level 0 instead of just showing the level 0 results. Are you looking for something like this? assignments[d] = a + b; assignments[e] = b c; assignments[f] = d e; assignments[x_] := x; FixedPointList[Map[assignments, #, {-1}] &, {f}][[;; -2, 1]] {f, d e, b ... 2 Maybe I missed the point, but if you just copy and paste your expressions (and insert spaces to give multiplication) you get: d = a + b; e = b c; f = d e which gives you b (a + b) c, which is equivalent to your given f. Is this all you were asking? 1 Because in your first case, Map[func,l] will evaluate to verbatim l while building up the replacement rules. When the replacement is then done, the replacement rule used is x[l_] -> l. My guess why Map[func, l] evaluates the way it does is that Map works by "inserting" func into it's second argument at the default mapping level, 1. As there is no such ... 5 Looking at your code, the problem occurs when you're trying to return {node-1, Transpose[{xn,phi}]}. If instead you run the following code, which only returns Transpose[{xn,phi}], calU=Compile[{{x,_Real,1},{energy,_Real},{m,_Real},{a,_Real}}, Module[{i,node,xn,nn,phi,V,h,f,temp}, h=x[[3]]; xn=Range[x[[1]],x[[2]],h]; nn=Length@xn; ... 5 Behavior you're describing is briefly mentioned in last paragraph of "Controlling Infinite Evaluation" tutorial and very similar example is shown in documentation of Update function. It's related to how Mathematica optimizes evaluation, how it decides that expression has not changed since last evaluation and whether it needs to be re-evaluated. For what ... 1 This kind of problem is the reason I sought and found a solution to: How do I evaluate only one step of an expression? Here is an example of how the step function defined in my answer there is used: var1 = "init-val1"; var2 = "init-val2"; mapping := {var1 -> "val1", var2 -> "val2"} (* note use of := *) step[mapping][[{1}, 1, 1]] % // ... 0 Here comes a simple solution, perhaps. The two cases characterize the usage well. expr = Sqrt[f[y[qq], z]^2] + Sqrt[DD[2, 3, 4]^2] + (f[1, 2] > 0); FullSimplify[expr, Thread[Cases[expr, x_[___] /; ! ValueQ[x], Infinity] > 0]] FullSimplify[expr, Thread[Cases[expr, f[___] /; ! ValueQ[f], Infinity] > 0]] Out[94]= True + DD[2, 3, 4] + f[y[qq], z] ... 1 This might be what you want: myfullsimplify[expr_, assum_] := Module[ {pat, tmp, seq}, pat = FirstCase[Level[assum, Infinity], p[_]] /. p[x_] -> x; tmp = FirstCase[Level[expr, Infinity], pat]; seq = {expr, assum} /. {pat -> #, p[_] -> #}; FullSimplify @@ seq /. # -> tmp ] It's used as follows: myfullsimplify[entry[1, 2, 3] < 0, ... 2 (this is wiki answer, as just noticed it is duplicate, but will keep it here for easy reference) The result is different from Version 2.2 and version 10.1, this is just to show the difference. Something changed between 1993 and today: 4 You need to construct your desired expression without unwanted evaluation of its constituent parts. Here is one approach to do that: makeTest[{tests__}] := Replace[And[tests] &, fn_ :> fn[#], {2}] This works because the surrounding Function prevents evaluation before and after the Replace operation. Example: f1[x_] := (Print["First"]; x > ... 6 It seems that when the book appeared, the behaviour of how a symbol is resolved was different. We have two important things: the current$Context which is usually Global` unless you change it with e.g. Begin as you did the \$ContextPath which is a list of contexts that are searched when you type in a symbol like x without explicit context Now there seems ...

7

I believe it is important to get a fundamental understanding of what Pure Functions are that goes beyond the understanding using of a syntax. Hereafter an non-exhaustif summary of a few key understandings: 1) Pure Functions have they roots in Lambda calculus that forms the basis of functional programming paradigm implemented in Mathematica. 2) In ...

18

Try this: Map[If[#==1,Unevaluated@Sequence[],#]&,{1,2,3}] Note the output. The 1 is gone. That's because Unevaluated@Sequence[] puts the empty sequence there, that is, "nothing". ##&[] is a shorthand that can be used in most places for same - ## is the sequence of arguments, & makes it a function to apply to something, [] is that something - ...

2

So much wrong there... a = 2; tx = 2^(3/2); x[t_] := a Cos[2 Pi t/tx] - Cos[2 Pi t]; y[t_] := a Sin[2 Pi t/tx] - Sin[2 Pi t]; f[t_] := x[t] + I y[t]; f[20] (* -1 + 2 Cos[10 Sqrt[2] π] + 2 I Sin[10 Sqrt[2] π] *) Don't use uppercase initials for your symbols - you might clash with built-ins. Don't use some external user-defined global symbol inside a ...

0

If you want the two solutions for each i: r = {}; eqns = {Table[y[i]'[t] == 15 - (Exp[i]*10*Exp[-2*t] + 3)*y[i][t], {i, 0, 3}], Table[With[{ii = i}, {y[i][0] == 5, WhenEvent[y[ii][t] == 3, AppendTo[r, {ii, t}]]}], {i, 0, 3}]}; sol = NDSolve[eqns, ...

0

Flatten[Table[NSolve[(y[i][t] /. sol) == 3, t], {i, 0, 3}], 2] (* {t -> 1.00734, t -> 1.5086, t -> 2.0086, t -> 668.12} *)

0

result = ReplacePart[first, Thread[Rule[Position[first, a], t]]] ListPlot[Transpose[{t, result}]]

3

first = {1 + a, 2 + a, 3 + a, 4 + a}; t = {0, 1, 2, 3}; MapThread[#1 /. a -> #2 &, {first, t}] (* {1, 3, 5, 7}*) or #[[1]] /. a -> #[[2]] & /@ Transpose@{first, t} (* {1, 3, 5, 7}*)

7

The r.h.s of the assignments are evaluated sequentially. However, the symbols don't actually assume these OwnValues until the the evaluation of the body of Block begins. Example: In[8]:= Block[{a = (Print[{a, b, c}]; 1), b = (Print[{a, b, c}]; 2), c = (Print[{a, b, c}]; 3)}, {a, b, c}] During evaluation of In[8]:= {a,b,c} During evaluation of In[8]:= ...

Top 50 recent answers are included