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

1 回表示 (過去 30 日間)
Alexander Holman
Alexander Holman 2016 年 11 月 8 日
コメント済み: Alexander Holman 2016 年 11 月 9 日
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

採用された回答

KSSV
KSSV 2016 年 11 月 9 日
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 件のコメント
Alexander Holman
Alexander Holman 2016 年 11 月 9 日
Thank you so much! Is the part where
Yv = [-Y(i) 0 0; 0 Y(i) 0; 0 0 Y(i)];
Really necessary?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by