Tag Info

New answers tagged

1

Clear[f] f[n_ /; EvenQ[n] && n > 0, x_] := 1 f[n_ /; OddQ[n] && n > 0, x_] := x


4

You can use Boole like this: xn[n_Integer?Positive] := x^Boole[OddQ[n]]


3

CircleDot[a_, b_] := (a + b) a b Now 4⊙3 84


2

Others have shown you ways to do what you want in ways which are more common to Mathematica. But I think what you really ask for (though it might not necessarily the best solution for your problem) is "pass by reference" which as such does not exist in Mathematica. But there is the possibility to use Attributes for functions and using e.g. HoldFirst will ...


3

Wouldn't it be easier to use Part? a = {{2, 3}, {4, 5}}; a[[1, 2]] = -a[[1, 2]]; a {{2, -3}, {4, 5}}


2

You can use ReplacePart data = RandomReal[{}, {2, 2}] data = ReplacePart[data, {1, 2} -> -data[[1, 2]]] You need to reassign the result back to data You can make the above into a function if needed. flip[data_, i_, j_] := ReplacePart[data, {i, j} -> -data[[i, j]]]; data = flip[data, 1, 2] In your function, you also did something wrong. ...


3

The total derivative Dt will give you an answer assuming every symbol has a derivative, unlike the partial derivative D. To protect your constant, you can give it the attribute Constant. SetAttributes[a, Constant] f = a Sin[q]; Dt[f, t] (* a Cos[q] Dt[q, t] *)


1

One way to guard against this kind of thing is to use an interpolating function: x = {0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5}; fx = {1, 2, 3, 4, 5, 6, 7}; f = Interpolation[Transpose[{x, fx}]] Table[f[t], {t, 0.2, 0.5, 0.05}] {1., 2., 3., 4., 5., 6., 7.}



Top 50 recent answers are included