nonlinear matrix equation solving in matlab - matlab

is it possible to solve below equation in matlab?
A*X+B*exp(X)=C
A, B are square and constant matrices. C is a constant and column matrix.
X is a column matrix which should be found.( exp() acts element by element on X).

If you are looking for a numeric method, you might want to try fsolve
X = fsolve( #(x) A*x + B*exp(x) - C, x0 );
Due to the non-linear nature of the problem you need to provide an initial guess x0 - the quality of which can affect the performance of the solver.

Related

A\b or b\A for A*x=b in MATLAB

A solution of A*x = b can be obtained by x = A\b. But I did x = b\A as I did not look for exact syntax. I got different vectors x in with A\b and b\A. I understood that A\b is more or less equivalent to inv(A)*b, but I don't understand what exactly is happening if I do b\A. Does anyone know about it?
From the MATLAB documentation:
If A is a rectangular m-by-n matrix with m ~= n, and B is a matrix with m rows, then A\B returns a least-squares solution to the system of equations A*x= B.

Diagonalizing Matrix in Matlab Gives "Wrong" Linear Combination of Eigenvectors

In Matlab, I'm trying to solve for the energies and eigenstates of a Hamiltonian matrix which has a highly degenerate set of eigenvectors. The matrix is a 55x55 hermitian matrix, and when I call either eig or schur to do the diagonalization I find that some (but not all) of the eigenvectors are the "wrong" linear combinations within each degenerate subspace. What I mean by "wrong" is that there are additional constraints in the problem. In this case, there is a good quantum number, M, which I want to preserve by not allowing states with different M values to be mixed--- but that mixing is exactly what I see when I run the code. Is there a way to tell Matlab to diagonalize the matrix while simultaneously maintaining the eigenvectors of another operator?
you can use diag to diagonalize a matrix and [eig_vect,eig_val] = eig(A) to give you eigenvectors.
I don't know matlab well enough to know whether there is a routine for this this, but here's how to do it algorithmically:
First diagonalise H, as you do now. Then for each degenerate eigen-space V, diagonalise the restriction of C to V, and use this diagonalisation to compute simulaneous diagonalisations of C and H
In more detail:
I assume you have an operator C that commutes with your Hamiltonian H. If V is the eigen-space of H for a particular (degenerate) eigen value, and you have a basis x[1] .. x[n] of V , then for each i, Cx[i] must be in V, and so we can expand Cx[i] in terms of the x[], and get a matrix representation C^ of the restriction of C to V, that is we compute
C^[k,j] = <x[k]|C*x[j]> k,j =1 .. n
Diagonalise the matrix C^, getting
C^ = U*D*U*
Then for each row (r1,..rn) of U* we can form
chi = Sum{ j | r[j]*x[j]}
A little algebra shows that this is an eigenvector of C, and also of H

Piecewise linear optimisation using matlab

I want to solve the following optimisation problem, whose objective function is independent of x:
minimise t
subject to a_i*x+b_i<=t
over x for all i from 1 to n=100
This problem arised from if I rewrite a piecewise linear optimisation problem to a linear optimisation problem.
Question:
How can I implement this in the matlab using linprog. In linprog I am asked to insert the objective function f as a matrix multiplying with x. Is it possible to have a objective function independent of x? If not, how am I going to implement this?
P.S: I don't know why Mathjax is not working here, I have been looking for how to ask questions with Math formula, but I was not successful. Therefore any correction is welcomed.
Edit:Here is the official document from Matlab for linprog. In it it is stated that the minimalising function has the shape of f^Tx. My problem is just that my minimalising function doesn't take such shape and is in the absence of x. How can I implement this in the Matlab?
You need to reformulate your problem into standard LP, i.e. find the nominal f, A and b as required by MATLAB's function linprog.
Here is the reformulation. From your question it seems x and t are two scalars.
Assume the given a_i's and b_i's are stored in column vectors a and b respectively, then your original problem:
min t, s.t. a * x + b <= t * ones(n,1)
is equivalent to:
min [0; 1]' * [x; t], s.t. [a, ones(n,1)] * [x; t] <= -b.
Thus, just use linprog([0; 1], [a, ones(n,1)], -b), and the solution is [x; t].

How to solve A*X - X*A' = 0

I have an equation of the form A*X = X*A', where A and X are real, square matrices (3x3 in that case) and A is known and A' represent the transpose of A. How to solve for X using MATLAB? (up to a scale factor)
This is a Sylvester equation. However, it is singular because the eigenvalues of A and A' are the same. But you can use the formulae
[I⊗A-A'⊗I]X(:)=C(:):
m=kron(eye(3),a)+kron(-a,eye(3))
v=null(m)
x1=reshape(v(:,1),[3 3])
x2=reshape(v(:,2),[3 3])
x3=reshape(v(:,3),[3 3])
Now the solution is span{x1,x2,x2}, i.e. any matrix of the form
b x1 + c x2 +d x3, where b,c,d are any real numbers
I don't think Matlab has facilities for symbolic algebra.
If you expand A and X, and work through the expression, you obtain an 3x3 matrix with equation in several unknowns, all of which are zero. You then solve that.
But I don't think Matlab allows you to set a matrix to a symbol, rather than an value and expand it for you. For this simple case, you could easily write such a function, that multiples a string matrix by a numerical matrix. The snag is it's hard to scale it up to the general case without throwing the entire Maple / Mathematica engine at it.

how to solve MMV sparse representation with CVX

I want to solve multiple measurement vector (MMV) sparse representation problem with CVX toolbox. I have a N*L matrix X. matrix X have only a few nonzero rows. I have system of equations Y=A*X. Y is M*L matrix of measurements (M
min Relax(X)
subject to Y=A*X
Realx(.) is a function that applies norm 1 to the vector t. (N*1)vector t consists of the norm 2 of each rows of matrix X. i.e. Relax(X)= norm_1(t) and t(i)=norm_2(X(i,:))
I can’t transform my objective function into a language that CVX can understand and solve.
Please tell me how I should change the problem objective and constraints that CVX could solve it.
'norms' is the cvx command you're looking for. Suppose sigma is some known parameter that allows Y to be only approximately equal to A*X (e.g. I tried it with sigma=10e-6). Then you could use this code:
cvx_begin separable
variable X(n,n)
minimize( norms(X,2,1) )
subject to
norm(Y - A*X,2)<= 10*sigma
cvx_end