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

2 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

Alan Stevens
Alan Stevens le 24 Juin 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 commentaires
Vinothkumar Sethurasu
Vinothkumar Sethurasu le 2 Août 2021
Hello Alan,
Thanks for your wornderful support.
I have facing some results deviation between using syms & function handle.
I am sharing the script below.
>> Function handle
f = @(u) [1 -u*0.112;0 1]*[1 0;(1/1057.68) 1]*[1 -u*0.0358;0 1]*[1 0;(1/9.358) 1]*[1 -u*0.0578;0 1]*[1 0;(1/2113.281) 1]*[1 -u*0.2436;0 1]*[1 0;(1/10015.548) 1]*[1 -u*33.607;0 1];
for u = 0:5
P=f(u);
V(u+1,1)=P(1,2);
M(u+1,:) = [u^5,u^4,u^3,u^2,u,1];
end
coeffs = M\V;
r = roots(coeffs);
r=abs(r);
r=sort(sqrt(r));
>> With syms
syms u
f = [1 -u*0.112;0 1]*[1 0;(1/1057.68) 1]*[1 -u*0.0358;0 1]*[1 0;(1/9.358) 1]*[1 -u*0.0578;0 1]*[1 0;(1/2113.281) 1]*[1 -u*0.2436;0 1]*[1 0;(1/10015.548) 1]*[1 -u*33.607;0 1];
P=f(1,2);
R=vpasolve(P);
R=double(R);
R=sqrt(R);
The resulst from syms looks correct.
kindly give me a suggestion to avoid the resuls deviation in function handle.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by