Tag Info

New answers tagged

0

I encountered the same question. My approach is to take partial derivatives w.r.t. all variables to be linearized to construct the linearized expression, plus the constant term: (* Expression to be linearized in da, db, dc *) expr = da*db + da^2 + db^3 + dc + da*dc^2 + 12 (* Make List of all vars to be linearized *) ds = {da, db, dc}; (* Create list of ...


1

For highest efficiency, you should use the Listability of built-in functions in order to construct lists. Using this, you can do the following one-liner: a[n_, kappa_] := 2 Cos[(2 Pi/n) kappa Abs[Array[Subtract, {n, n}]]] a[5, 3] // MatrixForm $$\left(\begin{array}{ccccc} 2 & \frac{1}{2} \left(-1-\sqrt{5}\right) & \frac{1}{2} ...


0

As written your definition stops after the first "line" ending with ; You should use Module to localize your variables. Mathematica is case-sensitive and System Symbols will always start with capitals Function application uses square brackets: Abs[j - i] Indexing begins from one generally you should pass n as a parameter These issues corrected: getA[n_, ...


3

Do you mean this ? n = 5; getA[kappa_] := Table[2*Cos[(2*π/n)*(Abs @(i - j))*kappa], {i, 0, n-1}, {j, 0, n-1}] getA[3] //MatrixForm You may post the expected result from your Python code in order to make it easier finding a functional programming equivalent. EDIT, clean up: getA[n_,kappa_] := Table[2*Cos[(2*π/n)*(Abs @(i - j))*kappa], {i, 0, ...


3

I think you can move condition outside brackets: ClearAll[f]; f[x_Integer : 1] /; x >= 0 := {x}


2

The reason is, that the nicely formatted subscripts in the frontend looking like $c_f$ are no "real" variables, but are represented as Subscript[c,f]. You can see that, if you use FullForm on one of those subscript-lookalikes. Therefore, your code does end up trying to create the derivative of the Mathematica-function Subscript, but of course there is no ...



Top 50 recent answers are included