MATLAB Answers

How to handle a variable inside matrix without using syms toolbox?

4 views (last 30 days)
I have a application to have a variable inside a 2x2 matrix.
The matrix multiplication needs to be done with number 2x2 matrices with variables.
At the end, the final product matrix will have polynomial equatoins of the variable as its elements.
The roots of the polynomial equation at element (1,2), need to be evaluated.
The application need to be done without using syms toolbox.

Accepted Answer

Alan Stevens
Alan Stevens on 24 Jun 2021
Are you looking for somethig like this;
f = @(w) [1,-0.1409*w^2;0,1]*[1,0;1/286.48,1]*[1,-0.05493*w^2;0,1]...
*[1,0;1/1793.55,1]*[1,-28.99*w^2;0,1];
%
% The sixth order polynomial of f(1,2) can be written as
% a*w^6 + b*w^5 +...+ f*w + g;
%
% Let w take on values 0, 1, 2..6
% Then you would have 7 equations in the 7 unknowns, a, b etc.
%
% Now you have a system of linear equations that can be solved
% for the unknowns using simple matrix division.
%
% The resulting values are the coefficients of the polynomial
% the roots of which can be found using the roots function.
for w = 0:6
P=f(w);
V(w+1,1)=P(1,2);
M(w+1,:) = [w^6,w^5,w^4,w^3,w^2,w,1];
end
coeffs = M\V;
r = roots(coeffs);
disp('Coefficients')
Coefficients
disp(coeffs')
-0.0000 0.0000 0.0175 0.0000 -29.1858 0.0000 0
disp('Roots')
Roots
disp(r)
0 -195.4814 195.4814 -41.8216 41.8216 0.0000
% Check that the polynomial is, in fact, zero at the calculated values
disp('Check')
Check
for i = 1:7
F = f(r(w));
disp(F(1,2))
end
-1.7339e-27 -1.7339e-27 -1.7339e-27 -1.7339e-27 -1.7339e-27 -1.7339e-27 -1.7339e-27
  17 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by