Tag Info

New answers tagged

1

I would approach this specific straightforward example in a straightforward way. Eliminate your matrix using RowReduce[mm]; red=RowReduce[mm]]; red//MatrixForm $\begin{pmatrix} 1 & 0.&0.&0.&0.&0.&0.&0.&0.&0.&\\ 0 & 1 &0.&0.&0.&0.&0.&0.&0.&0.&\\ 0 & 0 &1 ...


1

I post here another way of doing this. Since the algorithm below builds a block matrix I suspect it is slower for large matrices than the previous answer (this was also indicated on my machine, when I tried it on some examples). My coding skills are however very limited, so the reason it is slower might be my fault. getIntersectionbasis[l1_, l2_] := ...


2

You'd need to row reduce the intersection set to remove linear dependencies it might have. The code below should handle this. getIntersectionBasis[] := {} getIntersectionBasis[{}] := {} getIntersectionBasis[{}, __] := {} getIntersectionBasis[__, {}] := {} getIntersectionBasis[l1_] := getIntersectionBasis[l1, l1] getIntersectionBasis[l1_, l2_, l3__] := ...


3

Another method is to use Array, the fourth parameter of which sets the function that combines expressions: m = RandomReal[9, {3, 3, 3}]; Array[m[[#]] &, 3, 1, Dot] {{606.041, 638.877, 525.972}, {1011.5, 1068.12, 856.671}, {532.56, 556.236, 435.836}} Equivalent to: Dot @@ m {{606.041, 638.877, 525.972}, {1011.5, 1068.12, 856.671}, {532.56, ...


1

productF = Block[{Times = Dot}, Product[#, #2]] &; Examples: m = Table[PauliMatrix[i], {i, 1, 3}]; productF[j, {j, m}] (* {{I, 0},{0, I}} *) productF[PauliMatrix[j], {j, 3}] (* {{I, 0},{0, I}} *) For better emulation of Product one may include the HoldAll attribute and accept additional Product iterators with: productF2 = Function[, ...


4

Matrix multiplication is built in in Mathematica. Just use the dot for multiplication. Here are two 2x2 matrices a = PauliMatrix[1] b = PauliMatrix[3] (* Out[49]= {{0, 1}, {1, 0}} *) (* Out[50]= {{1, 0}, {0, -1}} *) Here's a product a.b (* Out[53]= {{0, -1}, {1, 0}} *) and here is the product of the same factors in reverse order b.a (* Out[52]= ...


1

1- you can't use Set (=) try using Equal (==) 2- I don't see meaning of simplifying (you will go back to original expression) eq = 1 == DD/R eq[[1]] + U == eq[[2]] + U (*1 + U == DD/R + U*) Simplify[%] (*DD/R == 1*)


1

Having upgraded to Mathematica 10.0.0, it turns out that the Distribution library greatly facilitates the numerical simulation of boson-sampling experiments using the above PermanentCode` package. The built-in function KolgomorovSmirnovTest is particularly valuable; the Wikipedia entry Kolmogorov–Smirnov test provides a good introduction. The appended ...


1

checking the Head is another way, useful in a construct like this: alist = {{{1, 0}, {0, 1}}, {{0, 0}, {0, 0}}}; Quiet@Select[ {#, LinearSolve[#, {1, 0}] } & /@ alist , Head@#[[2]] == List & {{{{1, 0}, {0, 1}}, {1, 0}}}


1

LinearSolve will generate an error message when it fail. Hence you can catch those messages. Number of ways to do this. Here is an example. mat = {{0, 0}, {0, 0}}; b = {1, 0}; status = True; status = Check[LinearSolve[mat, b], False, LinearSolve::nosol] (* False*) So status can be checked for False. If it is not False, then it passed. So simply set ...


2

Eigensystem is already informed A = RandomReal[1, {1000, 1000}]; A += Transpose[A]; Eigensystem[A]; // AbsoluteTiming (* {1.034878, Null} *) Eigensystem[A + 0. I]; // AbsoluteTiming (* {2.645509, Null} *) Update: type detection timings: Needs["GeneralUtilities`"]; r = RandomReal[1, {100, 100}]; c = RandomComplex[1 + I, {100, 100}]; MatrixQ[r, ...


4

Ordering[Norm /@ Last @ N[Eigensystem[system]]]; gives you the ordering by norm. You can apply this on your eigenvalues and eigenvectors, e.g. Eigenvectors[system][[%]] EDIT To apply this on a list of matrices: (# &@Ordering[Norm /@ N[#]]) & /@ Eigenvectors[#] & /@ {mat1,mat2,...,matn}


4

Here is another solution, of course similar to that of wxffles, but using SolveAlways. The function takes any polynomial in one variable as argument and returns the list of coefficients. bernsteincoefficients[pol_] := Module[{t, n, a}, t = Variables[pol][[1]]; n = Exponent[pol, t]; Table[a[k], {k, 0, n}] /. SolveAlways[Sum[a[k] Binomial[n, k] ...


4

I'm not aware of any built in function, but here's one way to do it. bb[n_, k_, t_] := Binomial[n, k] t^(n - k) (1 - t)^k; A test cubic, and a sum of our basis functions: p = -(1/12) + (5 x)/8 - (17 x^2)/12 + x^3; s = Sum[a[k] bb[3, k, x], {k, 0, 3}] Now solve for the coefficients: Solve@Table[Coefficient[s, x, k] == Coefficient[p, x, k], {k, 0, 3}] ...


4

The magical words are Singular Value Decomposition. The singular vectors corresponding to small singular values form the kernel. Of course, Singular Value Decomposition is available in Mathematica as SingularValueDecomposition[]. As confirmed by Daniel Lichtblau, the built-in Tolerance option to NullSpace[] does it this exact way.


12

With the understanding that the criterion for including a point in the 3D matrix is that it has 3 unique domains in any of the 26 points surrounding a zero value in the watershed here is a simple way to extract the data. In the case where zero values in the watershed are in minority it may be the fastest approach to getting a list of points that fulfill the ...


3

rmQ = MatrixQ[#, Internal`RealValuedNumericQ] &; ClearAll[realB, real] real[m_ /; MatrixQ[m] && Norm[Im[m], \[Infinity]] == 0] := m realB[m_?rmQ] := m real[RandomReal[1, {3000, 3000}]] // Head // AbsoluteTiming (* {0.312443,List} *) realB[RandomReal[1, {3000, 3000}]] // Head // AbsoluteTiming (* {0.093755,List} *) See also: How to check if an ...


4

Update: after clarification I propose f[m_] := Block[{$Assumptions = Alternatives @@ Flatten@m ∈ Reals}, Conjugate[m[[1, 1]]] // Simplify] f[{{x, x^2}, {h[x], S[y]^2}}] (* x *) Previous test-based answer: From the documentation of MatrixQ Test if a matrix has real numeric entries: MatrixQ[{{Pi, Sin[1]}, {Cos[2], E}}, Im[#] == 0 &] ...


2

Maybe this will work for you. validNum = Except[_Complex, _?NumericQ]; f[m : {{validNum ..} ..}] := m f will accept a wide variety number forms but not complex numbers. f[{{1, 2.}, {3/4, π}, {5, 6}}] {{1, 2.}, {3/4, π}, {5, 6}} f[{{1 + I, 2.}, {3/4, π}, {5, 6}}] f[{{1 + I, 2.}, {3/4, π}, {5, 6}}] Nor will it accept forms that are not ...


1

Given a matrix: eta = ({{1, 0}, {0, -1}}); one can decompose this into three matrices in the following way: {u, w, v} = SingularValueDecomposition[eta]; (* Where the original eta is defined by: *) u.w.Transpose[v] (* = eta *) Another way, which more appropriately addresses your problem is to use Schur decomposition. eta = ({{1, 0}, {0, -1}}); {q, t} ...



Top 50 recent answers are included