Tag Info

Hot answers tagged

17

One way is to use an extra argument that acts as a switch. Clear[f]; f[0] = 1; f[1] = 1; f[n_, True] := f[n - 1] + f[n - 2] Example: f7 = f[7, True] (* Out[329]= f[5] + f[6] *) To proceed another step, can do a replacement. f7 /. f[aa_] :> f[aa, True] (* Out[330]= f[3] + 2 f[4] + f[5] *) Can use Nest to repeat this n times. Nest[# /. f[aa_] ...


7

Here is a trick that allows you to get exactly what you're looking for: FourierTransform[ InverseFourierTransform[ x/y DiracDelta[x - y], x, k], k, x] DiracDelta[x - y] What I did here is to apply the Fourier transform and its inverse, which is of course the identity and therefore is equivalent to the original expression. But in doing so, ...


7

If we are willing to confine ourselves to functions like the example f which: is defined using DownValues only, and has no special attributes such as HoldAll, etc. ... then the following lifting function might be useful: ClearAll[stepper] SetAttributes[stepper, HoldAll] stepper[f_Symbol] := Module[{rules, g} , rules = Rule @@@ ...


4

The answers are great. I wanted to add that the problem you are trying to solve fits way better with replacement rules than function definitions, so switching to those can provide a more understandable answer Clear[f]; frules = {f[0 | 1] :> 1, f[n_] :> f[n - 1] + f[n - 2]}; f[7] /. frules (* same as f[7]//ReplaceAll[frules] *) f[7] /. frules /. ...


3

The following gives what you intended: Refine[Expand[P[x, y]^2], (x|y|beta) \[Element] Reals] (* ==> Conjugate[z[y]]^2/E^((2*I)*beta*x) + 2*Conjugate[z[y]]*z[y] + E^((2*I)*beta*x)*z[y]^2 *) In cases where you can live with expansion of complex exponentials into Sin and Cos you can also use ComplexExpand[P[x, y]^2, z[y], ...


3

If you're using M10, you could do it with Inactivate (which formats more nicely in Mathematica than it does here in plain text.) Inactivate[f[7] /. #, f] &[DownValues[f]] (* Inactive[f][5] + Inactive[f][6] *) Then Nest it: Clear[step]; SetAttributes[step, HoldFirst]; step[e_] := step[e, 1] step[e_, n_] := Inactivate[Nest[Function[{x}, x /. #], e, n], ...


2

Coefficient[E^(I a (t - b)) // ExpandAll, E^(I a t)] (* Exp[-I a b] *)


2

If you are going to work with non-commutative algebras like the matrix multiplication I recommend you try the NCAlgebra package. << NC` << NCAlgebra` (2 a) ** (3 b) 6 a ** b P.S. In NCAlgebra all lowercase variables are non-commutative by default.


2

Not paticularly elegant for reading but with minimal programming effort we can write f[0] = a; f[1] = b; f[k_] := HoldForm[f[k - 1] + f[k - 2]] ff[n_] := NestList[ReleaseHold, f[n], n - 1] Example ff[7] // Column $\begin{array}{l} f[7-1]+f[7-2] \\ (f[5-1]+f[5-2])+(f[6-1]+f[6-2]) \\ (f[3-1]+f[3-2])+2 (f[4-1]+f[4-2])+(f[5-1]+f[5-2]) \\ b+3 ...


2

Here is a way of evaluating your integral analytically. Series expand the integrand, but hold out a factor x/(-1 + E^x) to ensure that the series can subsequently be integrated term by term — this factor is 1 at x = 0, and x E^-x as x -> Infinity. Keep only the first few terms of the series, which we will use to “spot the pattern”. ser = Series[(x ...


1

Let M = CAC^(-1), s(k) = - CAC^(-1)y(k) + B r(k) + D r(k+1) then the recursion becomes eq = y[k + 1] == M y[k] + s[k] The solution with the initial condition y[0]==y0 is sol = RSolve[eq && y[0] == y0, y[k], k] $\left\{\left\{y[k]\to M^{-1+k} \left(M \text{y0}+\sum _{K[1]=0}^{-1+k} M^{-K[1]} s[K[1]]\right)\right\}\right\}$ Extracting y[k] ...


1

DiracDelta must be inside an integral to have much meaning. From its documentation: "DiracDelta can be used in integrals, integral transforms, and differential equations. " Assuming[Element[y, Reals], Integrate[x/y DiracDelta[x - y], {x, -Infinity, Infinity}]] 1 Assuming[Element[x, Reals], Integrate[x/y DiracDelta[x - y], {y, -Infinity, Infinity}]] ...


1

In Mathematica 10 using << Notation` Notation[x' => xPrime] seems to work to "disconnect" x' from its meaning as a derivative. (Note- the Notation text used here represents entering using the Notation Palette. Mathematica interprets this to Notation[ParsedBoxWrapper[ RowBox[{"x", "'"}]] \[DoubleLongRightArrow] ParsedBoxWrapper["xPrime"] ] ...


1

h[f[0]] := f[0]; h[f[1]] := f[1]; h[f[x_]] := f[x - 1] + f[x - 2]; nst[n_, num_] := Total@Nest[Cases[#, f[y_] :> h[f[y]], Infinity] &,{f[n]}, num] Testing: Table[nst[10, j], {j, 0, 9}] // TableForm


1

For the moment leaving aside the wisdom of using Subscripts as Symbols in Mathematica it would appear that your immediate problem has nothing to do with Subscript at all but rather the behavior of Variables. Recall its definition: Variables[poly] gives a list of all independent variables in a polynomial. And observe that even when using true Symbols ...



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