Tag Info

Hot answers tagged

17

You can do: x[[2 ;; -2, 2 ;; -2]] = 0; x or ReplacePart[x, {i, j} -> 0 /; And @@ MapThread[Less, {{1, 1}, {i, j}, Dimensions@x}]]


11

Just another alternative. x - ArrayPad[ArrayPad[x, -1], 1] // MatrixForm


7

Although I believe that Kuba's first method is the best approach here is another: zerofill[a_] := a (1 - BoxMatrix[#/2 - 2, #]) & @ Dimensions @ a Now: Array[Times, {5, 8}] // zerofill // MatrixForm $\left( \begin{array}{cccccccc} 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\ 2 & 0 & 0 & 0 & 0 & 0 & 0 ...


7

This performs quite well on large matrices, seems to outrun the others I've tested so far: Module[{z = ConstantArray[0, Dimensions@#]}, z[[1, All]] = #[[1, All]]; z[[All, 1]] = #[[All, 1]]; z[[-1, All]] = #[[-1, All]]; z[[All, -1]] = #[[All, -1]]; z] & For really large arrays, it would behoove one to work in the sparse domain, where the ...


5

n = Dimensions[x]; ReplacePart[x, {i_, j_} /;2 <= i <= n[[1]] - 1 && 2 <= j <= n[[2]] - 1 :> 0] another way: MapAt[0 &, x, {2 ;; -2, 2 ;; -2}]


5

There is indeed a generic expression for (the essential part of) your integral which leaves the dimension n open. (We will use n istead of k and s = Sigma^(-1) for the matrix in the exponent). Main idea The main idea is to use the function Sequence (and, of course, delayed assingment). Consider an informal expression of the type Integrate[ ...


5

The two eigenvalues are degenerate. In general whenever you have degenerate eigenvalues there is arbitrariness in how to select the eigenvectors. You can construct a constant vector from the two degenerate eigenvectors like so: m = Import["https://dl.dropboxusercontent.com/u/63413473/ExampleMatrix.mx"]; {evals, evecs} = Eigensystem[m, -2]; You can check ...


4

The problem here can arise because of numerical underflow which appears for sufficiently large dimension of the problem. Some numerically very small number multiplies the parameter "a" and therefore "a" does not appear in the "solution". Consider a simple example Define the matrix m (fill it with random numbers, here exponentially distributed) In[263]:= ...


4

This bug has been fixed in V10 mat = {{7/2 - I/2, -1 + I, 1/2 + 5 I/2}, {-1 + I, 5 + I, -1 + I}, {1/2 + 5 I/2, -1 + I, 7/2 - I/2}}; Eigensystem[mat] Gives: {{6, 3 + 3 I, 3 - 3 I}, {{1, -2, 1}, {1, 1, 1}, {-1, 0, 1}}} \begin{array}{ccc} 6 & 3+3 i & 3-3 i \\ \{1,-2,1\} & \left\{1,1,1\right\} & \{-1,0,1\} \\ \end{array}


3

<< SymbolicC` << Developer` << CCompilerDriver` << CCodeGenerator` Please don't mind these unnecessary abstractions. type = "mint"; abstractFunctionName = "makeMatr"; mainFunctionName = abstractFunctionName <> "I_T"; argumentSingletonGetterFunctionName[type_String] := StringJoin["MArgument_get", type]; getter = ...


3

A variation on @rasher's post: border = Module[{a = ConstantArray[0, Dimensions@#], i = {1, -1}}, {a[[i]], a[[All, i]]} = {#[[i]], #[[All, i]]}; a] & border@x //MatrixForm and another SparseArray variation border2 = Module[{a = ConstantArray[0, Dimensions@# - 2], d = Dimensions@#}, # SparseArray[Band[{2, 2}] ...


2

All the good answers are given. For fun, here is one using SparseArray {n, m} = Dimensions[x]; x = SparseArray[{{i_, j_} /; j == 1||j == m||i == 1||i == n} :> {x[[i, j]]}, {n, m}]; MatrixForm[x]


2

# ArrayPad[ConstantArray[0, Dimensions@# - 2], 1, 1] &@ Array[Times, {5, 8}] or # SparseArray[# -> 1 & /@ Flatten[{#, Reverse@# } &@ {_, #} & /@ {1, -1}, 1], Dimensions@#] &@ Array[Times, {5, 8}]


1

Much has already been said about this problem, but maybe this solution still might be helpful. First we define an auxiliary vector In[18]:= va = Array[a, 3] Out[18]= {a[1], a[2], a[3]} with which it is trivial to calculate the cross product: In[19]:= Cross[va, {1, 2, 3}] Out[19]= {3 a[2] - 2 a[3], -3 a[1] + a[3], 2 a[1] - a[2]} Now we replace the ...


1

This may not be your intention, however, please note Mathematica 9.0 has built-in MultinormalDistribution, where you can enter covariance matrix $\mathbb\Sigma$. For example: mnd = MultinormalDistribution[{1, 2, 3}, {{2, 1/2, -1/3}, {1/2, 1, 0}, {-1/3, 0, 2/3}}]; funs = {Mean, Variance, Skewness, Kurtosis, Composition[MatrixForm, Correlation]}; ...


1

As Oska has commented N is a protected symbol. Some other approaches: n = 4; mat = ConstantArray[1, {n, n}]; ReplacePart[mat, {{2, 3} -> 23, {4, 3} -> 43}] gives: {{1, 1, 1, 1}, {1, 1, 23, 1}, {1, 1, 1, 1}, {1, 1, 43, 1}} or Normal@SparseArray[{{2, 3} -> 23, {4, 3} -> 43}, {n, n}, 1] gives: {{1, 1, 1, 1}, {1, 1, 23, 1}, {1, 1, 1, 1}, ...


1

n = 4; A = ConstantArray[1, {n, n}] A[[2, 3]] = 23; A[[4, 3]] = 43; A {{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1}} {{1,1,1,1},{1,1,23,1},{1,1,1,1},{1,1,43,1}} n = 4; A = ConstantArray[1, {n, n}]; (A[[Sequence @@ #]] = FromDigits@#) & /@ Flatten[Table[{i, j}, {i, 1, 4}, {j, 1, 4}], 1]; A // MatrixForm $\left( \begin{array}{cccc} 11 & 12 & ...


1

I don't think you can "follow" the steps taken, but you surely can see how the resulting matrix is formed by "augmenting" your matrix with the identity. Following the last example on the docs about RowReduce[]: m = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}; a = Transpose[Join[Transpose[m], IdentityMatrix[Length[m]]]]; MatrixForm[r = ...



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