How to make a function to plot values of a Matrix?

2 vues (au cours des 30 derniers jours)
Alexander Holman
Alexander Holman le 8 Nov 2016
For a linear system A*x = B where A and B are known
Yv = [-Y 0 0; 0 Y 0; 0 0 Y];
A = [5 -4 4; -5 4 3; 5 3 1];
AY = A + Y; % ALSO TRIED USING: Instead of AY Y= [(5-Y) -4 4; -5 (4+Y) 3; 5 3 (Y+1)]
B = [1; 4; -2;];
inverseA = inv(AY);
x = inverseA*B; %vector x must satisfy
for n = 1:size(B)
xr = x(n);
% resultxt = 'Value %2.0f of vector x is %6.3f \n' ;
% fprintf(resultxt, n, xr)
a = x(1);
b = x(2);
c = x(3);
This returns me x1 x2 and x3 for the matrix in forms of a b and c respectively. I am trying to plot the values of x1 for
Y = linspace (1,12)
which does not work given that the (vector) sizes don't match. Any ideas? Thanks

Réponse acceptée

KSSV
KSSV le 9 Nov 2016
Y = linspace(1,12) ;
a = zeros(size(Y)) ;
b = zeros(size(Y)) ;
c = zeros(size(Y)) ;
for i = 1:length(Y)
Yv = [-Y(i) 0 0; 0 Y(i) 0; 0 0 Y(i)];
A = [5 -4 4; -5 4 3; 5 3 1];
AY = A + Y(i); % ALSO TRIED USING: Instead of AY Y= [(5-Y) -4 4; -5 (4+Y) 3; 5 3 (Y+1)]
B = [1; 4; -2;];
inverseA = inv(AY);
x = inverseA*B; %vector x must satisfy
% x = A\B ;
for n = 1:size(B)
xr = x(n);
% resultxt = 'Value %2.0f of vector x is %6.3f \n' ;
% fprintf(resultxt, n, xr)
a(i) = x(1);
b(i) = x(2);
c(i) = x(3);
end
end
hold on
plot(Y,a,'r')
plot(Y,b,'b')
plot(Y,c,'g')
legend([{'a'}, {'b'},{'c'}])
  1 commentaire
Alexander Holman
Alexander Holman le 9 Nov 2016
Thank you so much! Is the part where
Yv = [-Y(i) 0 0; 0 Y(i) 0; 0 0 Y(i)];
Really necessary?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by