Tag Info

11

Maybe upperTriangularMatrixQ2[mat_?MatrixQ] /; Equal @@ Dimensions@mat := UpperTriangularize@mat == mat; test = RandomInteger[{1, 100}, {1000, 1000}]; upperTriangularMatrixQ@test // AbsoluteTiming {2.126050, False} upperTriangularMatrixQ2@test // AbsoluteTiming {0.003277, False} test2 = UpperTriangularize@test; upperTriangularMatrixQ@test2 ...

9

You did not specify if this test should be optimized for the positive or negative case. If most of your matrices will fail the test it can be greatly beneficial to have an early exit behavior. For example if the lower left element in the matrix is not zero you can fail the matrix after a single element test! And even in the positive case the elements on ...

8

Every expression in Mathematica is characterized by it's FullForm. So in your case particularly FullForm[Log[x*x]]===Log[Power[x,2]] and FullForm[2*Log[x]]===Times[2,Log[x]] These two, although equivalent from a Mathematical point of view (but only if x>0) they have different FullForm representations. So SameQ(===) checks if the expression trees are ...

3

I just checked the documentation in V10 and accidentally stumbled upon a built in command: SQLConnectionOpenQ[conn] This seems to do the trick.

3

My apologies to those who closed this question for my unilaterally reopening it, but there is a nontrivial aspect to this question that I wish to address, and it would not nicely fit in comments. (I am not making an exception for myself; when someone has such an answer he wishs to give to a closed question I nearly always reopen it for him to do so.) ...

3

Jump straight down to Update 2 for the final code. I'll leave the previous iterations here as they explain how that solution developed. This is based on the following definition of similarity: Two expressions are similar if they become identical when all variables are replaced by the same generic variable. For example, both $a+b$ and $b+c$ become ...

3

In your code p_ simply means a pattern (Blank[]) that you want to name p. Normally this (giving it a name) is done because you want to do something with the matched pattern. The point here is that you are not testing for a subscripted variable that starts with p. You code is essentially equivalent to MemberQ[pars2, Subscript[\[Tau], _]] which is why you get ...

3

I don't know if I understand well, but if you want to check, with Mathematica on Unix, if a given file/directory is executable, you'll have to run a specific external unix command line and retrieve the result. Unix useful commands The following concerns UNIX systems but there are probably some equivalent commands for Windows. (Feel free to edit the post if ...

2

Primary fixes: Adding First to fidelPhase and adding t to Subscript[u, i, j][t]. Making an objective function obj that is not evaluated until a and b are numeric may or may not be important. I won't have time to check it out (I've lost track of the original optimizer). The following works and it's not crucial to be so precise in one's fixes. ...

1

data = {I (a^2 + b^2) (*1*), a (I b + e) (*2*), b (I a + d) (*3*), b (I a + f) (*4*), a b (*5*), a (I b + f) (*6*), I (b^2 + c^2) (*7*)} systemnames = Names["System`*"]; test[expr_] := Select[{Extract[expr, #], #} & /@ Position[expr, _Symbol, Infinity], MemberQ[systemnames , ToString@(#[[1]])] &] Gather[data, test[#1] == test[#2] ...

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