New answers tagged matrix
1
See if this is what you're after. I took the liberty of simplifying your MaximizeFunction, and in the process it became about twice as fast. I also got rid of the initial capitals. Best to avoid them, and avoid conflicting inadvertently with built-in functions.
In a comment you indicate that it might be sufficient to find the maximum over orthogonal ...
2
(Edit, I've edited the following almost entirely from the original, but the idea remains the same)
From the comments it seems that a single solution will be enough. You want the input of the original function to be a numerical matrix. You can set up a test for this as follows:
matrixnumQ[exp_] := MatrixQ[exp, NumericQ]
Then defining your original ...
7
I think this question is reasonably a duplicate of: How to find rows that have maximum value? (or several similar questions) and I will delete this answer if it is closed as such. Nevertheless, again for reference:
SeedRandom[1];
a = RandomInteger[{-3, 5}, {20, 5}]
Pick[a, Negative @ a[[All, 3]]]
{{-2, 1, -3, 4, -3}, {-2, 0, -1, -2, 3}, {1, 0, -3, -2, ...
4
m = RandomInteger[{-1, 1}, {10, 10}];
m1 = Select[m, #[[3]] < 0 &];
Show it:
ArrayPlot[#, ColorRules -> {1 -> Red, 0 -> Blue, -1 -> Yellow, _ -> Gray}] & /@ {m, m1}
1
Im trying to find the eigenvectors of an 11*11 matrix but can't get it to recognise my data [closed]
mydata={{1,2},{3,7}};
Eigenvectors[mydata]
{{-(7/3) + 1/3 (4 + Sqrt[15]), 1}, {-(7/3) + 1/3 (4 - Sqrt[15]), 1}}
1
1
You can teach Mathematica to factor out any number from inside a dot.
Unprotect[Dot];
x__.(c_?NumberQ y__) := c x.y
(c_?NumberQ x__).y__ := c x.y
Protect[Dot];
4
If you already have you matrix in component form, i.e. you have it broken into submatrices, then it is straightforward to construct a block diagonal matrix of any size.
Clear[BlockDiagonal]
BlockDiagonal[a : {_?MatrixQ ..}] :=
ArrayFlatten[
DiagonalMatrix[Range[Length@a]] /. i_Integer?Positive :> a[[i]]]
(* Convenience notation *)
...
1
Paraphrasing Anon, achieving greater clarity not really.
r = Flatten /@ Flatten[MapIndexed[Map[
Function[p, {#2, p}], Position[#, Min@#]] &, m], 1]
{{1, 5}, {2, 3}, {3, 1}, {4, 5}}
c = Flatten /@ Flatten[MapIndexed[Map[
Function[p, {#2, p}], Position[#, Max@#]] &, Transpose[m]], 1]
{{1, 1}, {2, 4}, {3, 2}, {3, 3}, {4, 1}, {5, ...
7
SparseArray[
Rescale /@ m - Rescale /@ Transpose@m\[Transpose] //
IntegerPart]["NonzeroPositions"]
2
Assuming that a saddle point of a matrix is an element that is the largest value of its column and also the smallest value of its row, it can be found out like this:
m = {{9, 3, 1, 8, 0},
{6, 5, 4, 6, 7},
{2, 4, 4, 3, 8},
{5, 6, 2, 2, 1}}
mt = Transpose[m]
m1 = Boole[With[{min = Min[#]}, # == min & /@ #] & /@ m]
m2 = Boole[With[{max = Max[#]}, ...
3
You will need to make pnorm into a black-box function so that it never tries to evaluate symbolically. Also it is probably worthwhile to use NMinimize/NMaximize in both. Finally the minimax process seems to behave better if you take pth powers in the inner optimization.
pnorm[aa_, p_] /; MatrixQ[aa, Element[N[#], Reals] &] := Module[
{m, n, x, y, f, ...
2
If this really can be expressed linearly, then expressing in Matrix form is going to be the easiest thing and the best from a computational perspective. For example, with your definitions:
R6 = kf*(z[1] + mu*z[5]) - 2*z[6] + mu*kd^2*z[7] - kd^2*z[6];
R7 = kf*(z[1] + mu*z[6] - 2*z[7]) + kd^2*z[8] + kd^2*z[7];
R8 = kf*z[1] + (mu*z[7] - 2*z[8]) + kd^2*z[9] + ...
1
Does this do the job?
poly=(kz py + py + kr kx)
variables = Variables[poly];
reprule =DeleteCases[If[StringTake[ToString[#], 1] == "k", # ->
Subscript[StringTake[ToString[#], 1],
StringTake[ToString[#], {2, -1}]]] & /@ variables, Null]
poly/.reprule
This will take all the variables in an expression, work out if they are a combination of k ...
3
Ok, so, thanks to Spawn1701D's comment here's the simplest way to proceed :
A={{{0, 1}, {1, 1}},{{-1, 0}, {0, 0}}};
res={q1,q2}.#.{q1,q2}&/@A;
final={q1p,q2p}+res;
To state it simple, Spawn1701D prescribes the usage of pure functions to make it extremely terse :
# function creates a slot between the two versions of the $\mathbf q$ vector
/@ is a ...
3
With ImageData[]. Like this:
MatrixPlot@ImageData@EdgeDetect@ExampleData[{"TestImage", "Lena"}]
7
Calculating eigenvalues involves solving for the roots of the characteristic polynomial, which is of degree equal to the order of the size of the matrix. When you input real numbers, it can search for the roots of the polynomial using numerical techniques. When you input exact integers (or rationals, probably) it tries to find exact answers for the roots of ...
0
There are of course many possibilities to achieve what you want. Here is one which imports and then rearranges, of course that will only work if you know how many columns per matrix there are:
data = Insert[#, "|", 8] & /@
Import[ToFileName[{$HomeDirectory}, "R1"], "Table",
"FieldSeparators" -> {" ", ",", "\t"}]
Here is another method which ...
1
A way to do this is to use rules. You have four things that can happen, so you can write four rules to substitute.
data//. {"0\t0" -> {0, 0}, "1\t0" -> {1, 0}, "0\t1" -> {0, 1}, "1\t1" -> {1, 1}}
Then you need to reshape the data. Flatten the output of the above and then partition it into the matrices of the correct size:
data2 = ...
5
Taking a page from kptnw's fine answer, here's one possibility:
Cross[Unevaluated /@ PauliMatrix[Range[3]], Range[3]]
3
Another idea to shorten the notation for the cross product in the special case where you have a Pauli matrix vector as the first argument is this:
ClearAll[OverVector];
OverVector /: Cross[OverVector[σ], x_?VectorQ] :=
x.LeviCivitaTensor[3].PauliMatrix[Range[3]]
Cross[OverVector[σ], {x, y, z}]
(*
==> {{{-y, -I z}, {I z, y}}, {{x, -z}, {-z, -x}}, {{0, ...
1
An alternative is to use Fold[] along with Dot[]. Using Jens's example, you can do Fold[Dot, IdentityMatrix[2], matrixList]. Note that your initial identity matrix must have dimensions that conform with the dimensions of your other matrices.
1
you normalize by the 3rd and the 4th element by the sum of these two elements, right?
Based on that, we might not want to use Normalize and divide directly:
#/{1, 1, #[[3]] + #[[4]], #[[3]] + #[[4]]} & /@ m
4
If you consider only real unit vectors then one can parametrize them in spherical coordinates u = {Sin[t] Cos[f], Sin[t] Sin[f], Cos[t]}; this way you can then use ParametricPlot.
Example :
SeedRandom[6]
a1 = With[{tmp = RandomReal[{-1, 1}, {3, 3}] + I RandomReal[{-1, 1}, {3, 3}]},
0.5 (tmp + ConjugateTranspose[tmp])];
a2 = With[{tmp = ...
3
String matching works a little better. Think of each row in the board as a string on the alphabet {"0", "1"}. The "pattern" is a set of instructions to look for particular configurations of "0" on the board, because a presence of a "1" in the pattern is no restriction at all and a "0" in the pattern means there must be a corresponding "0" on the board. ...
9
As $P$ is explicitly constructed from eigenvectors of a self-adjoint matrix, it is unitary, i.e $P P^\dagger = I\qquad$ where the $\dagger$ is the conjugate transpose (or Hermitian conjugate, if you prefer). So, calculating the inverse is simply ConjugateTranspose[P] which is much faster than calculating it using Inverse. That said, you have to ensure that ...
5
It seems I misunderstood the question. Here's an update, which is a considerable improvement, too. It relies on Implies[x, y] being equivalent to Boole[x] (1 - Boole[y]) == 0.
falsePattern = Table[False, {15}, {15}];
truePattern = Table[True, {15}, {15}];
SeedRandom[1];
randomPattern = RandomChoice[{True, False}, {15, 15}];
impliesPosition[board_, ...
4
tableImplies[a_, b_] := And @@ Flatten@MapThread[Implies, {a, b}, 2]
usage
a = Table[aa[i, j], {i, 2}, {j, 2}];
b = Table[bb[i, j], {i, 2}, {j, 2}];
tableImplies[a, b]
(*
(aa[1, 1] \[Implies] bb[1, 1]) &&
(aa[1, 2] \[Implies] bb[1, 2]) &&
(aa[2, 1] \[Implies] bb[2, 1]) &&
(aa[2, 2] \[Implies] bb[2, 2])
*)
9
There is a new function as of version 9 :
Series[MatrixFunction[(1 - a*(#))^(-1) &, bigM + bigS], {a, 0, 3}]
While the output does not look very pretty it will behave correctly.
5
Is
$$\begin{split}
1+&(M+S) \, a\\
+&(M\cdot S+S\cdot M+M\cdot M+S\cdot S) \, a^2\\
+&(M\cdot M\cdot S+M\cdot S\cdot M+M\cdot S\cdot S\\
&+S\cdot M\cdot M+S\cdot M\cdot S+S\cdot S\cdot M+M\cdot M\cdot M+S\cdot S\cdot S) \, a^3\\
+&O\left(a^4\right)
\end{split}$$
what you're expecting for? If yes, please continue read.
First we define a ...
9
Be explicit and do it in two steps. The first step is just the series computation with the matrix expression M+S replaced by a single variable:
f = Series[(1 + t x)^(-1), {t, 0, 3}]
$1-x t+x^2 t^2-x^3 t^3+O[t]^4$
We need to describe how to expand powers of x. This can be done recursively:
power[a_, n_Integer] /; n > 1 := Distribute[a . power[a, ...
1
This really is an inner product, and can be written straightforwardly using the Inner command:
Inner[Times, Transpose[Inner[Times,{2, 4},{{r1, r2}, {r3, r4}}, Plus]], {6, 8}, Plus]
3
As it stands, the dimensions of the tensor {{{1, 2, 3}, {3, 2, 1}}, {{2, 3, 1}, {2, 1, 3}}} are compatible with the vector on the left, but not on the right. We thus have
{3, 4}.{{{1, 2, 3}, {3, 2, 1}}, {{2, 3, 1}, {2, 1, 3}}}
{{11, 18, 13}, {17, 10, 15}}
and we now want to form the product of this with {6, 8} in some way. One could certainly do ...
1
This seems simpler than your method with Hold:
Block[{r1, r2, r3, r4},
{2, 4}.{{r1, r2}, {r3, r4}}.{{6}, {8}}
]
{{172, 160, 172}}
Also see:
Ways to compute inner products of tensors
Top 50 recent answers are included


