Hot answers tagged

31

Mathematica does not support this directly. You can do things of this sort using an external package called NCAlgebra. http://math.ucsd.edu/~ncalg/ The relevant documentation may be found at http://math.ucsd.edu/~ncalg/DOWNLOAD2010/DOCUMENTATION/html/NCBIGDOCch4.html#x8-510004.4 In particular have a look at "4.4.8 NCLDUDecomposition[aMatrix, Options]" ...


21

The documentation for MATLAB's mrdivide states that The operators / and \ are related to each other by the equation B/A = (A'\B')' In light of this we may write: LinearSolve[Transpose[A], b] This question was also answered by Daniel Lichtblau here. The equivalency follows from the following two properties of the transpose: $$ \left(A^\mathrm{-1}\...


19

I just stumbled upon it! At least when storing the factorization in a LinearSolveFunction object, we can use it for the transposed solve by supplying a further (not documented?) string variable to it: When calling sol[b, 1234] with a LinearSolveFunction object sol, Mathematica tells us that it only accepts the strings "N", "T", "C", and "J". As it is the ...


14

For a general square matrix m and arbitrary partition of it into conformable parts m={{a,b},{c,d}} (i.e., a and d are square matrices, and b and c have appropriate dimensions), the formula for the inverse (which can be found in, for example, Review of Matrix Algebra) is m={{a,b},{c,d}}; e = d - c.Inverse[a].b; minv={{Inverse[a] + Inverse[a].b.Inverse[...


14

Let's make this a little more challenging: invThread[body : _[h_[___] ..]] := Replace[Thread[body, h], _[x_ ..] :> x, {1}] f[{a, b}, {x, y}, z]; % // Thread % // invThread {f[a, x, z], f[b, y, z]} f[{a, b}, {x, y}, z]


13

Well, numerical approach is at least straight forward, though maybe a bit tedious to make perfectly automated. Here is a crude start. I will deal only with real part of your function. Find the table of points and flip point pairs: invf = Re@Table[{f[r], r}, {r, 0.001, 5, .01}]; gr = Show[ListLinePlot[invf, PlotStyle -> Red], Plot[{r, Re@f[r]}, {r, 0, 5}...


13

Henrik has already written on the undocumented second argument of a LinearSolveFunction[], so let me just put out a short demo wrapper showing how to use the built-in, but undocumented LAPACK routines to solve a linear equation, given the output of LUDecomposition[]: Options[backsub] = {Mode -> Automatic}; backsub[lu_, perm_, opts : OptionsPattern[]][...


12

Here's a nice one-liner: TransformationFunction[{{1, 0, 0, 0}, {0, 0, -1, 0}, {0, 1, 0, 3}, {0, 0, 0, 1}}] // InverseFunction TransformationFunction[{{1, 0, 0, 0}, {0, 0, 1, -3}, {0, -1, 0, 0}, {0, 0, 0, 1}}] Note that TransformationFunction[] is the head of the results returned by geometric *Transform functions, which take a homogeneous transformation ...


11

In general this is not an easy thing to do, and a package as Daniel Lichtblau suggested may be your best bet. However in the specialized case of a 2^n x 2^n matrix, the inversion is very well known. The case mentioned in your post is: Clear[sInverse]; (* s for symbolic *) sInverse[{{a_, b_}, {c_, d_}}] := {{Inverse[a], -Inverse[a] . b . Inverse[d]},...


11

If you have a homogenous transformation matrix of the form $$\begin{bmatrix} \mathrm{R_{3 \times 3}} & \mathrm{d}_{3 \times 1} \\ 0_{1\times 3} & 1_{1\times 1} \end{bmatrix}$$ Then the inverse is given by $$\begin{bmatrix} \mathrm{R}^{-1} & -\mathrm{R}^{-1}\mathrm{d} \\ 0 & 1 \end{bmatrix}$$ Therefore, if your ...


11

The identity does not hold for x < -1: Plot[ProductLog[x*Exp[x]], {x, -5, 5}] FullSimplify[ProductLog[x*Exp[x]], x >= -1] x (* result in 10.1.0 under Windows *)


11

This is a little long for a comment, beside which it points out an unexpected difference probably resulting from subsystems evolving independently at different times. In addition to Henrik's comment that the code is uncompilable, there are two things to add. The most significant is how the quantity is computed, and the other is the usual difference between ...


10

The most convenient way to answer this question is by using InverseFunction which allows you to hide the details of finding the numerical inverse: g = InverseFunction[Function[{t}, Tan[t] - t]] Then your equation Tan[t] - t == a x can be solved by simply saying g[a x]


10

No, Log is the name of the function and Log[x] is the function applied to x. Using Log without the argument is accepted by the system because Log is a symbol just like any other, but it does not make any sense. The correct way to write it is Solve[Log[x]/x^2 == y, x] or Reduce[Log[x]/x^2 == y, x] The latter tries to give you full solution information, ...


9

My interpretation of the question is that you want to find $x$ for given $f$, $g_2$ and $g_1$. Then just define $F=f/g_1$ and differentiate with respect to $x$ on both sides: $\frac{d}{dx}F(x)=g_2(x)$ Now solve this equation for $x$. There's no integration involved.


9

First, for the sake of simplicity let's define eqs - the system of our interest : eqs = { x == p + R Cos[k], y == Cos[p] + R Sin[k], k == ArcTan[ 1/Sin[p]] }; Equations y = y(x) For this system we can find an explicit equation $\;y = y(x)\;$ only assuming R == 0, otherwise we could find only implicit solutions. Solve[ eqs /. R -> 0, ...


9

The determinant computation is a matter of memory use in terms of how much we want to store for subdeterminants of a Laplace expansion. Mathematica simply refuses to go that route after 11x11. YOu can do your own as below. myDet[mat_] /; Length[mat] <= 4 := Det[mat] myDet[mat_] := myDet[mat] = Sum[mat[[1, j]]*myDet[Drop[mat, {1}, {j}]], {j, Length[...


9

Let me demonstrate two approaches in this answer. P.J. Acklam (WayBack archive of his page) devised a not-too-long method to approximate the quantile of the Gaussian distribution, with absolute errors on the order of $10^{-9}$. I have tweaked the Mathematica implementation of Acklam's approximation by William Shaw so that one can obtain a compilable ...


8

Usually simplifying the result with appropriate assumptions gives desired result: m={{3, 2, 1}, {3, 1, 2}, {2, 3, -1}, {-(3/b), -(3/b^2) - 2/b, -(3/b^3) - 2/b^2 - 1/b}, {-(3/b), -(3/b^2) - 1/b, -(3/b^3) - 1/b^2 - 2/b}, {-(2/b), -(2/b^2) - 3/b, -(2/b^3) - 3/b^2 + 1/b}}; Simplify[PseudoInverse[m], b \[Element] Reals]


8

Clear[RaisedCosineDistribution] As with built-in distributions, you need to include the parameters in the distribution definition, and the constraints on the parameters as Assumptions in the ProbabilityDistribution RaisedCosineDistribution[μ_, s_] = ProbabilityDistribution[ 1/(2 s) (1 + Cos[((x - μ)/s) π]), {x, μ - s, μ + s}, Assumptions -> {...


8

InverseFunction operates on an abstract function, yielding an abstract, anonymous function. g[x] is not a function, but a formula. Just leave out [x]. On 11.3, MacOS: InverseFunction[g] (* 2 Log[1/2 (-#1 - Sqrt[4 + #1^2])] & *) Unfortunately, although it's an inverse, this doesn't appear to be the branch you want. More: You can get @Henrik ...


7

I think you're on the right track with Reduce. If the domain Reals is specified, Reduce will return results that can be converted to a Piecewise expression straightforwardly. Clear[f]; f[t_] = Piecewise[{{t/4, t < 0}, {t/2, t < 3}, {3/2 + (t - 3)*3, True}}]; invPW[f_] := Evaluate @ Module[{t}, Piecewise[ List @@ Reduce[# == f[t], t, Reals] /. {...


7

The easiest way is to evaluate this: SetOptions[EvaluationNotebook[], StyleDefinitions -> Notebook[{ Cell[StyleData[StyleDefinitions -> "Default.nb"]], Cell[StyleData[All], FontColor -> GrayLevel[1], Background -> GrayLevel[0]]}, Visible -> False, StyleDefinitions -> "PrivateStylesheetFormatting.nb"] ] However as you ...


7

You can plot curves defined by implicit equations using ContourPlot: ContourPlot[ Cos[Sqrt[y]] + Sin[Sqrt[y]]/Sqrt[y] == Cos[x], {x, 0, 10}, {y, 0, 10}]


7

This seems usable at least for moderately large x. one could use cutoffs and different start values if this is not useful in smaller ranges. f[x_?NumberQ] := y /. FindRoot[LogIntegral[y] == x, {y, x*Log[x]}, WorkingPrecision -> 20, PrecisionGoal -> 12] Two examples: f[10^200] (* Out[55]= 4.6565831394119416907*10^202 *) NIntegrate[n/(f[n])^2, ...


7

I don't know that you can do it in a single command. But it's easy enough to do in two. Say your list is list={2,1,4}; x = ConstantArray[0, Max[list]]; x[[list]] = 1; x {1, 1, 0, 1} Effectively, Part (or the shortcut [[ ]]) acts as an approximate inverse of Position.


7

I like to use NDSolve to find inverses when symbolic methods won't work. The ODE corresponding to the inverse of a function g can be obtained by differentiating the defining equation: eqn = g[ginv[h]] == h; D[eqn, h] g'[ginv[h]] ginv'[h] == 1 So, to find the inverse using NDSolve, we need the above equation and an initial point. For example: ginv = ...


7

Out of curiosity, I tried to write my own version of inverse CDF for the normal distribution. I employ a qualitative approximation of the inverse CDF as initial guess and apply Newton iterations with line search until convergence. This is the code: f[x_] := CDF[NormalDistribution[0, 1], x]; finv[y_] := InverseCDF[NormalDistribution[0, 1], y]; p = 1/200; q =...


7

Inverse functions can be plotted using ParametricPlot or ParametricPlot3D Clear["Global`*"] F[alpha_, x_] = Assuming[{Element[x, Reals], -1 < x < 1}, Integrate[1/Sqrt[(x^2 - 1)^2 + alpha*x], x] // FullSimplify]; Manipulate[ ParametricPlot[{ {Re@F[alpha, x], x}, {Im@F[alpha, x], x}, {Abs@F[alpha, x], x}}, {x, -1, 1}, ...


6

The Mathematica documentation has a tutorial on eliminating variables that is helpful: http://reference.wolfram.com/mathematica/tutorial/EliminatingVariables.html Solve[{x == p + R*Cos[k], y == Cos[p] + R*Sin[k], k == ArcTan[1/Sin[p]]}, y, {p}] y -> Cot[k]^2 (R Sin[k] Tan[k]^2 - Sqrt[-Tan[k]^2 + Tan[k]^4]) Solving for y in terms of just x turns out ...


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