Is there a less time-consuming way to solve a Symmetric Matrix Equation - matlab

I'm currently working on solving an equation that involves a symmetric matrix C with 4 unknown variables, and a vector A of the same dimension. The equation I'm trying to solve is:
[C]*{A}=0 (1)
where * denotes matrix multiplication and { } denotes a vector.
The dimension of the C matrix can be as large as 100x100 or more, and I'm trying to define the unknown variables in C in a way that solves equation (1). One approach I've tried is to calculate the determinant of C, |[C]|=0, and solve for the 4 different variables inside.
However, when the dimension of the matrix is large, my current method in Mathematica is not able to solve the problem. I'm wondering if anyone has any suggestions for me to solve this equation more efficiently.
I'm open to using other programming languages such as Matlab or Python as well. Any suggestions or advice would be greatly appreciated.
Thank you in advance for your help and guidance.
I have tried solving this problem with 25*25 dimension. However, this size is not enough for the percision that I want for the variables.

Related

'solve' syntax in MATLAB for symbolic nonlinear matrix equation

I have a symbolic matrix that depends on a complex parameter q. Let the matrix be A(q) and b a column vector. I would like to simultaneously solve the equations
A*b==0; b'*b==1;
using the solve command (preferably the numerical variant vpasolve). The variables to be found are both b and q. I am not quite sure about the syntax on how to do this and would appreciate any help on it. My main problem is that the equation is partially given in matrix form and the searched variable is a vector.
Do I have to resort to fsolve to achieve this? Or is there a way without defining a function?

Matlab: Reduce second order matrix differential equation to standard eigenproblem

I want to obtain the natural frequencies of a simple mechanical system with mass matrix M and stiffness matrix K (.mat-file -> Download):
Mx''(t)+Kx(t)=0 (x= Position).
It means basically, that I have to solve det(K-w^2*M)=0. But how can I solve it in Matlab (or if necessary reduce it to a standard eigenvalue problem and solve it then)? The matrices are definitely solvable with Abaqus (FEM Software), but I have to solve it in Matlab.
I tried the following without success: det(K-w^2*M)=0 => det(M^-1*K-w^2*I)=0 (I := unity matrix)
But solving this eigenvalue problem with
sqrt(eigs(K*M^-1))
delivers wrong values and the warning:
"Matrix is singular to working precision.
In matlab.internal.math.mpower.viaMtimes (line 35)"
Other wrong values can be obtained via det(K-w^2*M)=0 => det(I/(w^2)-M*K^-1)=0:
1./sqrt(eigs(M*K^-1))
Any hint would help me. Thanks in advance.
As #Arpi mentioned, you actually want to solve the generalized eigenvalue problem:
K*x = w^2*M*x
Since your matrices K and M are apparently singular (or just one of them), it is not possible to use eigs, but you have to use eig:
V = eig(K,M);
w = sqrt(V);

What is benefit to use SVD for solving Ax=b

I have a linear equation such as
Ax=b
where A is full rank matrix which its size is 512x512. b is a vector of 512x1. x is unknown vector. I want to find x, hence, I have some options for doing that
1.Using the normal way
inv(A)*b
2.Using SVD ( Singular value decomposition)
[U S V]=svd(A);
x = V*(diag(diag(S).^-1)*(U.'*b))
Both methods give the same result. So, what is benefit of using SVD to solve Ax=b, especially in the case A is a 2D matrix?
Welcome to the world of numerical methods, let me be your guide.
You, as a new person in this world wonders, "Why would I do something this difficult with this SVD stuff instead of the so commonly known inverse?! Im going to try it in Matlab!"
And no answer was found. That is, because you are not looking at the problem itself! The problems arise when you have an ill-conditioned matrix. Then the computing of the inverse is not possible numerically.
example:
A=[1 1 -1;
1 -2 3;
2 -1 2];
try to invert this matrix using inv(A). Youll get infinite.
That is, because the condition number of the matrix is very high (cond(A)).
However, if you try to solve it using SVD method (b=[1;-2;3]) you will get a result. This is still a hot research topic. Solving Ax=b systems with ill condition numbers.
As #Stewie Griffin suggested, the best way to go is mldivide, as it does a couple of things behind it.
(yeah, my example is not very good because the only solution of X is INF, but there is a way better example in this youtube video)
inv(A)*b has several negative sides. The main one is that it explicitly calculates the inverse of A, which is both time demanding, and may result in inaccuracies if values vary by many orders of magnitude.
Although it might be better than inv(A)*b, using svd is not the "correct" approach here. The MATLAB-way to do this is using mldivide, \. Using this, MATLAB chooses the best algorithm to solve the linear system based on its properties (Hermation, upper Hessenberg, real and positive diagonal, symmetric, diagonal, sparse etc.). Often, the solution will be a LU-triangulation with partial permutation, but it varies. You'll have a hard time beating MATLABs implementation of mldivide, but using svd might give you some more insight of the properties of the system if you actually investigates U, S, V. If you don't want to do that, do with mldivide.

Matrix equation in Matlab

I have a matrix equation and I want to solve it in MATLAB. The equation is
X^(-1)AX=B.
Where X is an unknown symmetric 3x3 matrix, A is known and B is a diagonal matrix (There isn't any condition on B's elements, just diagonal).
Please help me solve this problem!
From the information you've given it appears that you are looking for a symbolic solution which Matlab is not the best at (usually Mathematica is prefered or check out Wolfram Alpha). If you absolutely need Matlab then you could use the 'solve()' command.
However, honestly you are dealing with a rather simple linear system of small dimensions so it is probably easiest to just work this out by hand. Check out Matrix Cookbook for help. Also it really just looks like you are just trying to solve for the eigenvector matrix so possibly the command eig() might help ??

Minimizing error of a formula in MATLAB (Least squares?)

I'm not too familiar with MATLAB or computational mathematics so I was wondering how I might solve an equation involving the sum of squares, where each term involves two vectors- one known and one unknown. This formula is supposed to represent the error and I need to minimize the error. I think I'm supposed to use least squares but I don't know too much about it and I'm wondering what function is best for doing that and what arguments would represent my equation. My teacher also mentioned something about taking derivatives and he formed a matrix using derivatives which confused me even more- am I required to take derivatives?
The problem that you must be trying to solve is
Min u'u = min \sum_i u_i^2, u=y-Xbeta, where u is the error, y is the vector of dependent variables you are trying to explain, X is a matrix of independent variables and beta is the vector you want to estimate.
Since sum u_i^2 is diferentiable (and convex), you can evaluate the minimal of this expression calculating its derivative and making it equal to zero.
If you do that, you find that beta=inv(X'X)X'y. This maybe calculated using the matlab function regress http://www.mathworks.com/help/stats/regress.html or writing this formula in Matlab. However, you should be careful how to evaluate the inverse (X'X) see Most efficient matrix inversion in MATLAB