New answers tagged

5

FunctionRange[{-a* Log[1 - (a - a E^(-1 - 1/a + ProductLog[E^(1 + 1/a)]))/a], a > 0}, a, y] 5.14988*10^-9 <= y <= 0.5 and warming message: Unable to find the exact range. Returning bounds on the range computed using numeric optimization methods So we have to consider Derivative FunctionRange[{D[-a* Log[1 - (a - a E^(-1 - 1/a + ...


3

Limit[v[a], a -> 0, Direction -> -1] (* 0 *) Limit[v[a], a -> Infinity] (* 1/2 *) NMaximize[{v[a], a > 0}, a, WorkingPrecision -> 100] (* {0.4999999999999999999999999999999996695802781800686528047791793409305\ 917941358131704720756957033359931, {a -> 1.89153358206810035345892896405454026939268176767953621670767804301\ ...


0

The problem: ln(...) should be Log[...]. Furthermore, the endpoints in Plot should be different, so you cannot use a = 0. f[a_Real, x_Real] := x*(1 + a*Log[1 - x/a]) Manipulate[Plot[f[a, x], {x, 0, a}], {a, 0.05, 20, 0.05}]


5

In the following simplistic benchmark, passing a single argument-list g[{x1,x2,x3,...,xn}] is about 100×–1000× faster than passing arguments separately f[x1,x2,x3,...,xn] when using large numbers of arguments: f[x__] := Total[{x}] (* slow: call as f[x1,x2,x3,...,xn] *) g[x_] := Total[x] (* fast: call as g[{x1,x2,x3,...,xn}] *) SeedRandom[...


1

Essentially you are asking if Function[{x1, x2}, f[x1, x2]] [x1, x2] is better in some sense than Function[x, f[x[[1]], x[[2]]]]@ {x1, x2} with respect to optimizing speed, memory, and coding "safety". With regard to speed and memory, it is possible to test performance with controlled experiments. With regard to coding "safety", that is ...


0

First, I would like to give this credit to Alexei Boulbitch. He made a little but critical amend in the input argument of my original code. The function should be defined as following , instead, st[txt_String] := Style[ToExpression[txt, TeXForm, HoldForm], 18, FontFamily -> Times, Bold] In this way, the input of the function could be a string and the ...


6

Function does not do pattern matching. If you need pattern matching, you can do it manually: Function[x, Switch[x, a|b, 1, _, 0 (* this is the default choice for input that don't match preceding patterns *) ] ] Note that it is not possible to keep Function[...] unevaluated when there is no match.


2

The immediate problem with linearize[ f[x_, #]& ] is that you are trying to define sub-values for Function: f[x_, #]& is equivalent to Function[f[x_, #]], so linearize will try to do Function[f[x_, #]][pre___, 0, ___] := 0 This attempts to assign the definition to Function, which is Protected, hence the error. If you want some kind of a ...


4

We can compute the distance matrix by explicitly computing the pairwise distances. dist[dim1_, dim2_] := NetGraph[{"rep1" -> ReplicateLayer[dim2], "tr" -> TransposeLayer[], "rep2" -> ReplicateLayer[dim1], "subtract" -> ThreadingLayer[(#1 - #2)^2 &], "sum" -> AggregationLayer[...


1

You can do either of the following result1 = 16 (y - x); result2 = x (45 - z) - y; result3 = x*y - 4 z; F[{x_, y_, z_}] := Evaluate[{result1, result2, result3}]; x = Array[a, 3]; F[x] Or result1 = 16 (y - x); result2 = x (45 - z) - y; result3 = x*y - 4 z; F[{x_, y_, z_}] = {result1, result2, result3}; x = Array[a, 3]; F[x] Both give same result you showed. ...


2

The correct way to draw some orbits for this map: With[{ε = 1.023, icv = Union[Table[{m, m}, {m, 0, 6, 0.1}], {{1.63, 0.41}, {5.23, 2.58}, {5.33, 2.64}, {5.43, 2.64}, {5.53, 2.64}, {5.63, 2.64}, {5.83, 2.64}, {5.25, 5.94}, {4.6, 5.3}, {4.6, 5.13}, {4.56, 4.85}, {4.6, 5.5}, {4.7, 4.3}, {1.5, 4.25}, {5, 2.2}, {1.57, 4.57}, {5.24, 2.17}, {1.68, 1....


1

Does the following do what you want? ClearAll["Global`*"] ReArrangedTable[xy_] := Join[{xy[[1]]}, Flatten[Table[{xy[[i]], xy[[i + 1]], FunctionValue[xy[[i]], xy[[1]]]}, {i, 2, Length[xy], 2}]]] SolutionInTableForm = {{x, 1, 2, 1, 3, 2, 7}, {x, 2, 3, 5, 1, 3, 9}, {x, 4, 5, 2, 9, 1, 1}}; MappedTable = Map[ReArrangedTable, ...


2

I think nothing will beat bestPrice[a_] := a/2; Why do I believe that this is true? Well, first I observed that U[x_, p_, a_] := 1 - Clip[(x + p)/a, {0, 1}] Now Simplify[Solve[x - U[x, p, a] == 0, x], {a >= p >= 0}] returns {{x -> Undefined}, {x -> Undefined}, {x -> ConditionalExpression[(a - p)/(1 + a), a > p && p > 0]}} ...


1

We can reduce time by 6.66 times (on my computer) using Module instead of functions with ?NumericQ price[a_] := Module[{x, v, p}, u = RegionMeasure[ ImplicitRegion[(a*v - p - x >= 0 && 0 <= v <= 1), {v}]]; Q = (x /. FindRoot[x - u == 0, {x, 0.00001, 0, 1}]); purchase = RegionMeasure[ ImplicitRegion[{(a*v - p - x >= 0 &...


1

When you use =, Mathematica evaluates the right hand side of your equation first - then sets the left hand side equal to that. So BP[z_, zeroes_List] = Product[z^Boole[a == 0], {a, zeroes}] * Product[((z - a)/(1 - a\[Conjugate]*z))^Boole[a != 0], {a, zeroes}] First calculates Product[z^Boole[a == 0], {a, zeroes}] * Product[((z - a)/(1 - a\[Conjugate]*z))^...


13

The issue is that to SetDelayed1 (:=), Function is just a normal head. For your third example, this means the following: You are defining a downvalue for F that says "every time you see F[something] replace it with the expression Function[x, 2 x + 1][x^2], where all x are to be replaced by something". Notice that at no point in that process is the ...


4

We need a general function that compares $f(a,b)$ with $f(-a,-b)$ and decides which one to prefer, for any choice of $(a,b)$. It's a matter of taste which form is more desired; here I use Sort (always picking the form that is higher in sorting order), which is unambiguous but may not be what you are looking for. rule = f[a_, b_] :> Last[Sort[{f[a, b], f[-...


Top 50 recent answers are included