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

조회 수: 2 (최근 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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by