How to coefmatrix in maxima - maxima

I have a 3x3 matrix. I am trying to separate out the variables from the constants in my matrix. I am aware I can use the function coefmatrix
Function: coefmatrix ([eqn_1, …, eqn_m], [x_1, …, x_n])
t1: Xd_x . Ta . Xdd_x;
q: list_matrix_entries(Xd_x . Ta . Xdd_x );
How to get the coefficient matrix for q with unknowns Ta(*,*)?

After a bit of experimenting, I could figure this out.
Following will do the trick. The important point is the matrix q need to be linear in the coefficients and make sure all the coefficients are given into 2nd argument.
A: coefmatrix( q, [Ta_00, Ta_01, Ta_02, Ta_10, Ta_11, Ta_12, Ta_20, Ta_21, Ta_22 ] )

Related

Maxima wrongly says a matrix is non-invertible

The below matrix matrix is clearly invertible modulo 3.
But Maxima returns false when I try to obtain its inverse.
0 1
1 1
What is wrong here?
M: matrix([0,1],[1,1]);
zn_invert_by_lu(M,3 );
According to doc:
zn_invert_by_lu (matrix, p)
Uses the technique of LU-decomposition to compute the modular inverse of matrix
over (Z/pZ). p must be a prime and matrix invertible. zn_invert_by_lu returns
false if matrix is not invertible.

Cannot solve this algebraic equation in Maxima?

Hello i am trying to solve a algebric equation in maxima, the equation has alpha, delta and psi as variable. I want the alpha in equation to be solved in terms of psi and delta. I tried using the solve command but i am getting alpha in terms of alpha.
Here is the equation to solve Equation to solve
And this is the output from maxima
.
This is the code i am trying -->
solve([(sqrt(-4*alpha*delta*psi-4*delta*psi+alpha^2*delta^2)/(delta^2+delta)-(alpha*delta/(delta^2+delta)))/2-sqrt(4*alpha^2*delta^2+6*alpha*delta^2+3*delta^2+2*alpha^2*delta+4*alpha*delta+2*delta)/(3*delta^2+2*delta)+alpha*delta/(3*delta^2+2*delta)=0],alpha);
Thank you
The problem with that algebraic equation is that involves square roots,or radicals and normal polynomial, and that that type of equation is not easy to solve, take a look at this equation:
(%i30) solve(x=sqrt(x+6),x);
(%o30) x = sqrt{x+6}
So Maxima doesn't return any value, but for example other software Mathematica does.
Let's square both sides of equation and try to solve it
(%i31) solve(x^2=x+6,x);
(%o31) x=3 , x=-2
we get two solutions, let's try with first equation:
3 = sqrt(3+6) => 3 = sqrt(9) => 3 = 3
-2 = sqrt(-2+6) => -2 = sqrt(4) => -2 = 2 ??????
So the second solution is not valid,
maxima solve program in Macsyma/Maxima generally avoids methods that
produce false solutions, like "square both sides". It may still
make errors based on dividing by expressions that appear to be
non-zero, but actually ARE zero, and maybe some other similar
situations.
from this mailing list
In your case I will factor the equation to get a simplified version but with those free variable this will be difficult so, try to assume some values for psi and delta:
(%i26) solve(factor((sqrt(-4*alpha*delta*psi-4*delta*psi+alpha^2*delta^2)/(delta^2+delta)-(alpha*delta/(delta^2+delta)))/2-sqrt(4*alpha^2*delta^2+6*alpha*delta^2+3*delta^2+2*alpha^2*delta+4*alpha*delta+2*delta)/(3*delta^2+2*delta)+alpha*delta/(3*delta^2+2*delta))=0,alpha);
(\%o26) \left[ \alpha=\ifrac{\left(3\,\delta+2\right)\,\isqrt{\left(-4\,\alpha-4\right)\,\delta\,\psi+\alpha^2\,\delta^2}+\left(-2\,\delta-2\right)\,\isqrt{\left(4\,\alpha^2+6\,\alpha+3\right)\,\delta^2+\left(2\,\alpha^2+4\,\alpha+2\right)\,\delta}}{\delta^2} \right]
Expand your Equation and try to remove square roots or some assumptions:
Equation : (sqrt(-4*alpha*delta*psi-4*delta*psi+alpha^2*delta^2)/(delta^2+delta)-(alpha*delta/(delta^2+delta)))/2-sqrt(4*alpha^2*delta^2+6*alpha*delta^2+3*delta^2+2*alpha^2*delta+4*alpha*delta+2*delta)/(3*delta^2+2*delta)+alpha*delta/(3*delta^2+2*delta);

Minimize a equation using opencv

I need to solve the following equation:
I Know the matrix G, how can I find the the matrix p subject to ||p|| = 1.
Currently I am solving in opencv as follows:
Mat w, u, EigenVectors;
SVD::compute(A, w, u, EigenVectors);
Mat p = EigenVectors.row(EigenVectors.rows-1);
I want to know how can I ensure the condition ||p|| = 1.
Also I want to know the significance and meaning of other rows/cols of the EigenVectors(transposed) ?
I believe you can use cv::SVD::solveZ(). It finds a unit-length solution x of a singular linear system A * x = 0
Looks like you need to use Lagrange multipliers method.
As I know, OpenCV have no ready to use tools for that.
Good example for MATLAB: Lagrange Multipliers

image derivatives using gaussian

this is the function I have for calculating the image derivatives. Please help me understand this code as I am new to this field. If anyone could give me some links to understand this concept, I'll be greatful. some doubts that i have -
Why are we using ndgrid here?
What are the directions 'x', 'y', 'xx', ('xy', 'yx'), 'yy' here?
And how and why does the formula for this gaussian change according to the directions?
Why are we using imfilter at the end?
function D =calc_image_derivatives(I,sigma,direction)
[x,y]=ndgrid(floor(-3*sigma):ceil(3*sigma),floor(-3*sigma):ceil(3*sigma));
switch(direction)
case 'x'
DGauss=-(x./(2*pi*sigma^4)).*exp(-(x.^2+y.^2)/(2*sigma^2));
case 'y'
DGauss=-(y./(2*pi*sigma^4)).*exp(-(x.^2+y.^2)/(2*sigma^2));
case 'xx'
DGauss = 1/(2*pi*sigma^4) * (x.^2/sigma^2 - 1) .* exp(-(x.^2 + y.^2)/(2*sigma^2));
case {'xy','yx'}
DGauss = 1/(2*pi*sigma^6) * (x .* y) .* exp(-(x.^2 + y.^2)/(2*sigma^2));
case 'yy'
DGauss = 1/(2*pi*sigma^4) * (y.^2/sigma^2 - 1) .* exp(-(x.^2 + y.^2)/(2*sigma^2));
end
D = imfilter(I,DGauss,'conv','replicate');
This code calculates various directional derivatives of the image - x/y are first directional derivative, xx/yy/xy are second derivatives. The digital filter used for derivation is a 2D Gaussian of standard variation sigma, derived by the appropriate partial derivative (for example, in the case 'xx', the Gaussian is derived twice by x). From your question, I'm not sure you're familiar with the notion of a partial derivative, you can Google it.
ndgrid is used to create grid matrices - this is a very commonly used approach in Matlab. Perhaps you know the function meshgrid, it is the same, only ndgrid can also create grid matrices of higher dimensions.
imfilter is used to perform a convolution (correlation to be more precise) between the digital filters to the image. The result of the this is an estimation of the required derivative.

How can I compute SVD and and verify that the ratio of the first-to-last singular value is sane with OpenCV?

I want to verify that homography matrix will give good results and this this answer
has an answer for it - but, I don't know how to implement the answer. So can anyone recommend how I may use OpenCV to compute SVD and and verify that the ratio of the first-to-last singular value is sane?
There are several ways to compute the SVD in OpenCV:
cv::SVD homographySVD(homography, cv::SVD::FULL_UV); // constructor
// or:
homographySVD(newHomography, cv::SVD::FULL_UV); // operator ()
homographySVD.w.at<double>(0, 0); // access the first singular value
// alternatives:
cv::SVD::compute(homography, w); // compute just the singular values
cv::eigen(homography, w);
Have a look at the documentation for cv::SVD and cv::eigen for more details.
You can compute SVD in python using numpy.
For example:
import numpy as np
U, s, V = np.linalg.svd(a, full_matrices=True)
which factors the matrix a of dimension M x N as u * np.diag(s) * v, where u and v are unitary and s is a 1-d array of a's singular values.
More can be found here.

Resources