Tag Info

Hot answers tagged

12

how to reproduce the default hashing behaviour when explicitly choosing a method Hash[1, "Expression"] (* 6568131406215528669 *) re-create the default hashing behaviour in different versions? Not possible as far as I know. The one-argument Hash implementation may change between versions. The algorithm has been most recently ...


9

Welcome in the amazing world of machine precision arithmetic! If you examine the binary representation of both numbers you see the following: RealDigits[1.2, 2] (* {{1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1}, 1} *) RealDigits[.2, 2] ...


8

The problem is that the function name f is substituted into Function (&) which is HoldAll. This means f[t] will not be evaluated until the Function is evaluated, such as in the OP's example problem[one][17]. So the trick is to evaluate the integrand before inserting it into the Function. Here is one way. one[x_] := 1 (*the argument*) problem[f_] := ...


6

Here is a partial answer. I believe for Method -> {opts}, opts may be any of the following, and they will have whatever effect they have: Internal`InequalitySolverOptions[] Internal`ReduceOptions[] Internal`NSolveOptions[] (* {"ARSDecision" -> False, "BrownProjection" -> True, "CAD" -> True, "CADAlgebraicCoefficients" -> True, ...


5

To directly get the opposite of Alternatives, you could negate each pattern with Except and then negate the Alternatives: also[patts__] := Except[Alternatives @@ Except /@ {patts}] Cases[Range[1, 15, 1/2], _Integer ~also~ _?(# > 10 &)] (* {11, 12, 13, 14, 15} *) Generally some other approach will be simpler, though, as discussed in the comments.


5

Implementing the suggestion of @Guesswhoitis in the comments: if the derivative of the inverse function is given by a function $x'(x)$, then the slope of the tangent line to the graph at $(x_0, y(x_0))$ will be given by $1/x'(x_0)$, and the line through the point $(x_0, y(x_0))$ will be $$ y = \frac{x - x_0}{x'(x_0)} + y(x_0). $$ Implementing: a = 112.941; ...


4

This is possibly a duplicate, but the answers given in most cases seem probably more in depth than the OP is looking for, being a newcomer to Mathematica. First you should define f as a function. f[e_] := 7.523190091795795`*^-18 (1.329223358440088`*^17 - 3.9876700753202693`*^18 e + Sqrt[-8.944600854152669`*^34 + 1.4311361366644287`*^37 e^2]); ...


4

What I think you are seeking: z[entropy_List] := beta \[Function] Evaluate[Sum[E^(entropy[[i, 2]] - beta entropy[[i, 1]]), {i, 1, Length[entropy]}]] Now: z[{{9, 1}, {3, 6}, {3, 4}, {4, 0}, {9, 5}}] Function[beta$, E^(1 - 9 beta$) + E^(5 - 9 beta$) + E^(4 - 3 beta$) + E^(6 - 3 beta$) + E^(-4 beta$)]


4

You can do the whole thing numerically by replacing the Heaviside function with a numerical version. For example: nHeaviside[x_] := If[x < 0, 0, 1] will work. You can choose which value it will assume at zero by changing the condition to x <= 0. Alterantively, the function Unitstep does a similar task: nHeaviside2[x_] := UnitStep[x] (Guess who ...


3

Probably. A = Array[a, {3, 4}]; functionTable = A + A f@# &; functionTable[x]


3

Sjoerd C. de Vries correctly diagnoses the problem and provides a resolution. An alternative is to work in exact numbers and convert to floating point at the end. Floor[Range[1, 2, 1/10], 2/10] (* Output: {1, 1, 6/5, 6/5, 7/5, 7/5, 8/5, 8/5, 9/5, 9/5, 2} *) N[Floor[Range[1, 2, 1/10], 2/10]] (* Output: {1., 1., 1.2, 1.2, 1.4, 1.4, 1.6, 1.6, 1.8, 1.8, 2.} ...


3

Alternatively, we could check to see if the derivative of the inverse is the reciprocal of the derivative of the original function. This will work nicely as long as your functions have neither vertical nor horizontal asymptotes. a = 112.941; b = 18.6588; f[x_] = a x (Cosh[b x^(1/4)/2] - 1)/(b x^(1/4) Sinh[b x^(1/4)/2]); fD[x_] = D[f[x], x]; fInverseD[x_] = ...


3

x is just your starting value for the iteration. The function to apply, and the stopping condition, should both be applied to the current value obtained by the iteration, and are probably best expressed using pure functions: collatz[x_] := NestWhileList[If[Mod[#, 2] == 0, #/2, #*3 + 1] &, x, # != 1 &] collatz[5] (* Out: {5, 16, 8, 4, 2, 1} *) ...


3

The following antilogarithm function works: antiLog[b_: E, z_] := b^z . Then the base can be changed via b & since the default for Log is E, antiLog[Log[x]] produces x. However, as GuessWhoItIs pointed out in the comments, Power[~] is worth looking into first. Power[~] is actually exactly equivalent to this. Similarly, your own cologarithm function ...


3

z[entropy_][beta_] := Sum[E^(entropy[[i, 2]] - beta entropy[[i, 1]]), {i, 1, Length[entropy]}]; f = z[{{1, 2}, {3, 4}}]; f /@ Range@5 (* {2 E, 1 + 1/E^2, 1/E^5 + 1/E, 1/E^8 + 1/E^2, 1/E^11 + 1/E^3} *) Avoid using uppercase initials for your own symbols, BTW... This still evaluates the sum, of course. You can achieve the desired goal with your ...


3

Your current syntax is trying to Map the function {2} onto each element in the list generated transform2Time[#,10] &/@ {lst2,lst2,lst3} I think this is what you want? ulttst = N@Map[transform2Time[#, 10] &, {lst1, lst2, lst3}, {3}]


3

As I see it, this behavior does not depend on Hold properties. In fact, PDF[NormalDistribution[]] evaluates to a Function, so you can apply it to arguments using []: Head[PDF[NormalDistribution[]]] (* Function *) On the other hand, (scale PDF[NormalDistribution[]]) does not evaluate to an expression with head Function; in fact, it evaluates to an ...


3

Yes, it is possible to get Mathematica to accept TeXForm input in raw form without quotes, using a method similar to the one described in this answer. Using $PreRead to intercept the input before it is interpreted by Mathematica and then convert it to a string, we can define the latextoma function as a replacement rule with $PreRead = (# /. ...


3

You need to create a pure Function and Map it over the first level of tstlst like so: LinearModelFit[#, x, x] & /@ tstlst Now tstlst can have as many sets as you like without you having to know how many in advance.


2

So I managed to get what I wanted, thanks a lot for your replies, I am pretty new to Mathematica and they helped a great deal. Here is my code: r3 = r1 r4 = r2 T = 0.01 T1 = T T2 = T T3 = T T4 = T GainD[r1_, r2_, r3_, r4_] := (r4*(r1 + r2) + r2*(r3 + r4))/(2*r1*(r3 + r4)) GainDiv[r1_, r2_, r3_, r4_, T1_, T2_, T3_, T4_] := (((((r4/(2 r1 (r3 + r4)) - ((r1 ...


2

I've cleaned up your code a bit and although I kept your variable names you should be warned that it is never a good idea to start your variables with an uppercase character as this may conflict with built-in names (that always start with a capital). r3 = r1; r4 = r2; T = 0.05; T1 = T; T2 = T; T3 = T; T4 = T; GainD[r1_, r2_, r3_, r4_] := (r4*(r1 + r2) + ...


2

For exactly the reasons mentioned in another answer, (scale PDF[NormalDistribution[]])[0.5] doesn't work since the Head of the expression is Times rather than Function. This suggests that we should replace the innards of the Function. Something like scale = 10; f = PDF[NormalDistribution[]] /. (Function[b_] :> Function[scale b]); Then f @ 0.5 results ...


2

If curve is given a non-numeric input the Part specification is not valid and we get: curve["atom"] Part::pkspec1: The expression 1+Floor[100 atom] cannot be used as a part specification. >> Since symbolic analysis may be used by many Mathematica functions, including plotting, you should restrict the input of your curve function to numeric values ...


2

To be honest, I was quite surprised that Mathematica finds an analytical solution when you just enter the problem in naively: Area[RegionIntersection[Disk[{l, 0}, l], Disk[{0, l}, l], Disk[{l/2, l/2}, l/2]]] On Mathematica 10.1 I don't get the expression with complex terms that Fernando got above, I get the purely real ConditionalExpression[-(1/4) ...


2

This eliminates the errors and displays some information. I do not know if this is everything you are looking for. functionname[x_] := Module[{}, Needs["Splines`"]; Needs["ErrorBarPlots`"]; SetOptions[InputNotebook[], PrintPrecision -> 10]; filelocation = SystemDialogInput["FileOpen"]; rawfiledata = Import[filelocation, "Table"]; ...


1

You need anonymous functions. The way it's written currently will replace every instance of x on the right hand side with the number you provide as the argument for collatz. What you want is something which can act on the value produced by NestWhileList on each iteration. So use Clear[collatz] collatz[x_] :=NestWhileList[If[Mod[#, 2] == 0, #/2, #*3 + ...


1

Perhaps this is what you are looking for. arry = Array[a, {4, 3}] {{a[1, 1], a[1, 2], a[1, 3]}, {a[2, 1], a[2, 2], a[2, 3]}, {a[3, 1], a[3, 2], a[3, 3]}, {a[4, 1], a[4, 2], a[4, 3]}} funcTable = Map[With[{a = #}, Function[x, a (1 + f[x])]] &, arry, {2}]; This shows how the functions in funcTable can be evaluated at an arbitrary value t. ...


1

Summarizing J.M.'s comments you could use: Do[ f[m] = Table[i/11 + j/m, {i, 5}, {j, 5}], {m, 9, 12} ]; f[11] // MatrixForm $\left( \begin{array}{ccccc} \frac{2}{11} & \frac{3}{11} & \frac{4}{11} & \frac{5}{11} & \frac{6}{11} \\ \frac{3}{11} & \frac{4}{11} & \frac{5}{11} & \frac{6}{11} & \frac{7}{11} \\ \frac{4}{11} ...


1

Usually one does not need what you ask for. E.g. a pattern for an even integer greater than 10: x_Integer?EvenQ /; x > 10 (_Integer is not strictly necessary here as only integers will pass EvenQ however it should make the pattern a bit more efficient.) But since it is an interesting quesiton here is one idea: matchAll[expr_, form_] := ...


1

The key here is to understand the Apply operator. There we want to apply f at level 1 to the list. Therefore, like Guess who it is suggested we can first apply the function f[x, y, z, ##] where ## gets filled in from your list because of the the @@@. Then Total adds up all the functions. Total[f[x, y, z, ##] & @@@ list]



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