# Tag Info

1

Here's how I would write your example, in a way that "jibes" with Mathematica. (* Define the functions in terms of parameters *) fun1[a_, b_][c_][x_] := a + b x + c fun2[a_, b_][c_][x_] := b + a x + c fun3[a_, b_][c_][x_] := fun1[a, b][c][x] + fun2[a, b][c][x] (* Specify the parameters' values *) a = 1; b = 2; c = {1, 4, 10}; (* Rather than loop, ...

0

This can be performed using the Quantum Mathematica add-on http://homepage.cem.itesm.mx/lgomez/quantum/ You can implement any commutator (or even anti-commutator) algebra of your choice. See here for an example with the algebra of Pauli matrices. It works flawlessly and I have used it quite extensively while working with algebras or super-algebras with ...

2

You can use Fold and switch i and v in your definition of h ... h[v_, i_] := ... Fold[h, v, Range] (* h[h[h[v, 1], 2], 3] *) ... or switch the order directly in Fold. h[i_, v_] := ... Fold[h[#2, #1] &, v, Range] (* h[3, h[2, h[1, v]]] *)

9

You can see why when you break it up. Since you use 1.1 then Mathematica evaluated it numerically. Compare v = 1 + I a = Abs[v] b = Exp[I Arg[v]] a*b With v = 1.10 + I a = Abs[v] b = Exp[I Arg[v]] a*b You see that Exp[I Arg[v]] now is 0.73994 + 0.672673 I To keep things nice, as your first example, use exact number v = 11/10 + I a = Abs[v] b = Exp[I Arg[...

1

Maybe the following? I didn't understand all the extra variables, so I stripped down the code more. In a complicated case, you might need Dynamic@Refresh instead of just Dynamic; see What is the point of Refresh if Dynamic has an UpdateInterval option? and related Q&A on Refresh. You'd probably have to put the output in a docked cell, since the FE ...

2

A slight variation using the Fold function (benefitting from Bob Hanlon's answer): lorentz[x_, x0_, linewidth_] := 1/Pi (1/2 linewidth)/((x - x0)^2 + (1/2 linewidth)^2) ; mol[J_, dB_] := dB * J (J + 1); linewidth = 0.1; dB = 0.1; fCombined[x_] = Fold[#1 + lorentz[x, mol[#2, dB], linewidth] &, 0, Range] // Together // FullSimplify The Fold ...

3

Blank ( _ ) is only used as a pattern object; it cannot be used in a variable name Clear["Global`*"] lorentz[x_, x0_, linewidth_] := 1/Pi (1/2 linewidth)/((x - x0)^2 + (1/2 linewidth)^2); mol[J_, dB_] := dB*J (J + 1); linewidth = 1/10; dB = 1/10; fCombined[x_] = Sum[lorentz[x, mol[J, dB], linewidth], {J, 1, 10}] // Together // ...

Top 50 recent answers are included