Irreducible polynomial in AES and GNU Octave - aes

In the Rijndael AES proposal in section 2.1.2 they have chosen m(x) = x^8 + x^4 + x^3 + x + 1 and said it is an irreducible polynomial. This polynomial corresponds to integer 283.
Further in section 4.2.3, they have defined the value of M, the matrix used in MixColumn operation. I was trying to find its multiplicative inverse M⁻¹ in octave. I used the command
y = gf(M, 8, 283)
And octave gave me the following error:
error: gf: primitive polynomial (283) of Galois Field must be irreducible
Can anyone please help me in explaining why I am getting this error? I have very little knowledge of fields, groups and similar abstract concepts.

Related

What type of operation should you use on single expressions containing vectors and numbers in Matlab?

I am trying to produce a contour plot of the following equation in Matlab.
theta=[(k+0.5)^2+t^2]^(-1/2)-[(k-0.5)^2+t^2]^(-1/2).
This is how I initially expressed it.
k=linspace(-1,1,20);
t=linspace(-0.5,0.5,20);
[K,T]=meshgrid(k,t);
Z=((K+0.5)^2+T.^2)^-0.5 -((K-0.5)^2+T.^2)^-0.5;
contour(K,T,Z, 'ShowText', 'on')
I'm getting the error message 'Input arguments for contour must be real.' so assuming I have expressed the equation wrong in the 4th line. I'm confused as to what type of operation I should use for expressions such as (K+0.5)^2+T.^2, where there are both vectors and numbers. How should I express it in Matlab syntax?
Apologies if the question is really basic. Absolute beginner.
The immediate error is because Z contains complex values (has non-zero imaginary components).
The real issue though is that you have used the matrix power (^) rather than an element-wise power (.^) in some places in your definition of Z.
Your expression to compute Z should actually be:
Z = ((K + 0.5).^2 + T.^2).^-0.5 - ((K - 0.5).^2 + T.^2).^-0.5;

Solving system of linear equations

My goal is to solve the system of equation known as Lyapunov equation, that is finding x in the following equation:
A*X + X*transpose(A) +Q = 0
plus another linear constraint that is X*v = 0
where all matrices A, X ,Q are n by n matrices and v is a vector with length n.
How can I find such X in matlab?
Solution
Solving Lyapunov equations in Matlab is very easy. Both the continuous and discrete Lyapunov equation have a built-in function:
Continuous Lyapunov equation: lyap (see Matlab documentation here)
Discrete Lyapunov equation: dlyap (see Matlab documentation here)
Extra note: if the links would not work, or you want a quick way to check the documentation of a Matlab function offline, every built-in Matlab function has a short help page reachable by help NameOfTheFunction.
Furthermore the extended help page, as also visible on the web, with examples can also be retrieved offline by typing doc NameOfTheFunction in the Matlab terminal.
Example
Given the following continuous Lyapunov equation:
A*X + X*transpose(A) + Q = 0
The solution in Matlab for a stable A and positive definite Q is given as:
X = lyap(A,Q)
In some cases the equation is slightly different:
A*X + X*B + C = 0
This equation calls the Sylvester equation and is again solvable with the built-in Lyapunov function of Matlab:
X = lyap(A,B,C)
The same analogue solution steps exist for the discrete case, where the Lyapunov and Sylvester equation look slightly different:
A*X*transpose(A) -X + Q = 0 -> X = dlyap(A,Q)
A*X*B - X + C = 0 -> X = dlyap(A,B,C)

Implementing simplex algorithm and getting "matrix singular to machine precision" error

I am implementing the (dual) simplex algorithm in Matlab/Octave.
My algorithm works just fine for a small test problem, but as soon as I try a bigger problem as afiro.mps (from http://www.netlib.org/lp/data/) I get the warning "matrix singular to machine precision, rcond=0" and octave throws an error (or does not terminate). The exact command is:
x = zeros(n,1);
x(B) = A(:,B) \ b; % Compute primal variables
y = A(:,B)' \ c(B); % Compute dual variables
The problem is in standard form
min c*x
s.t. Ax=b
x>=0
A is a m-x-n matrix and B is the index vector of the inactive constraints (base variables).
As I am doing a two phased simplex I choose 1:size(A,1) as an initial base for the dual simplex.
The problem is read from a mps file via a self coded reader. I expect the mps file is read correctly, as the glpk function solves the problem correctly, when it has A,b,c as input parameters.
Is there some way to avoid the warning or do I have an error in my coding?
The basis matrices of linear programming problems usually have very bad condition numbers. This is one the difficulties when implementing a stable simplex algorithm.
You should have a look at this paper that explains this phenomenon:
On the Factorization of Simplex Basis Matrices

Matlab: Binary Linear Programming

I am trying to solve some equations on Matlab using Binary Integer Programming.
I have 3 sets of equations:
Ma.X=1
Mp.X<=1
Mr.X<=m*
Where, Ma is a known matrix with size 5*12
X is unknown set with size 12*1
Also Mp is known matrix with size 5*12
and Mr is a known matrix with size 4*12.
1 in the equations is an unity matrix with size 5*1 in both sets(1&2)
m* is a given known matrix with size 4*1
I'm trying to use command bintprog but how to put 1 equality and 2 inequalities
to get values of X. Also I don't have Function f to insert, I just have set of equations. Given that X unknown values with values 1 or 0.
I tried this command bintprog([],Ma,One51,Mp,One51)
but it gives me The problem is infeasible. with zeros answer matrix.
Please help me to solve this on Matlab
The correct syntax for bintprog is X = bintprog(f,A,b,Aeq,beq).
If you don't have f (which means you just want any feasible point), you can set it to []. However, for the others, your syntax is slightly wrong.
I am assuming that the + in your constraints is actually a * since otherwise, the matrix algebra doesn't quite make sense.
Try this:
X = bintprog([],[Mp;Mr],[ones(5,1);mstar],Ma,ones(5,1))
If even then it tells you that the problem is infeasible; it might as well be true that there are no Xs that can satisfy all your constraints.

Multiplication of large number with small number

I'm trying to compute a rather ugly integral using MATLAB. What I'm having problem with though is a part where I multiply a very big number (>10^300) with a very small number (<10^-300). MATLAB returns 'inf' for this even though it should be in the range of 0-0.0005. This is what I have
besselFunction = #(u)besseli(qb,2*sqrt(lambda*(theta + mu)).*u);
exponentFuncion = #(u)exp(-u.*(lambda + theta + mu));
where qb = 5, lambda = 12, theta = 10, mu = 3. And what I want to find is
besselFunction(u)*exponentFunction(u)
for all real values of u. The problem is that whenever u>28 it will be evaluated as 'inf'. I've heared, and tried, to use MATLAB function 'vpa' but it doesn't seem to work well when I want to use functions...
Any tips will be appreciated at this point!
I'd use logarithms.
Let x = Bessel function of u and y = x*exp(-u) (simpler than your equation, but similar).
Since log(v*w) = log(v) + log(w), then log(y) = log(x) + log(exp(-u))
This simplifies to
log(y) = log(x) - u
This will be better behaved numerically.
The other key will be to not evaluate that Bessel function that turns into a large number and passing it to a math function to get the log. Better to write your own that returns the logarithm of the Bessel function directly. Look at a reference like Abramowitz and Stegun to try and find one.
If you are doing an integration, consider using Gauss–Laguerre quadrature instead. The basic idea is that for equations of the form exp(-x)*f(x), the integral from 0 to inf can be approximated as sum(w(X).*f(X)) where the values of X are the zeros of a Laguerre polynomial and W(X) are specific weights (see the Wikipedia article). Sort of like a very advanced Simpson's rule. Since your equation already has an exp(-x) part, it is particularly suited.
To find the roots of the polynomial, there is a function on MATLAB Central called LaguerrePoly, and from there it is pretty straightforward to compute the weights.