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

1 Ansicht (letzte 30 Tage)
Alexander Holman
Alexander Holman am 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

Akzeptierte Antwort

KSSV
KSSV am 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 Kommentar
Alexander Holman
Alexander Holman am 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?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by