How do I plot datas from the variable matrix.

Hello,
I am trying to solve below problem;
"Using MATLAB, investigate the nature of the variation of the principal values and directions over the interval 1 < x1 < 2. Formally plot the variation of the absolute value of each principal value over the range 1 < x1 < 2."
And here is what I've done so far:
clc;
clear all;
x=[1:0.1:2];
for i=1:length(x)
A(i,:,:)=[2*i,i,0;i,-6*(i^2),0;0,0,5*i]
% Calculate Invariants
invariants(i)=[trace(A),(trace(A)^2-trace(A*A))/2,det(A)]
[V,L]=eig(A(i))
% Principal Values are the Diagonal Elements of the L Matix
principal_values(i)=abs([L(1,1),L(2,2),L(3,3)])
% Principal Directions are the Columns of the V Matrix
principal_directions(i)=[V(:,1),V(:,2),V(:,3)]
end
I was able to handle the calculation part. But I could not able to plot that.
I need to plot each data in "principal values" vector in the range of 1 < x <2.
The result will be like this:
Thank you in advance.

댓글 수: 2

KSSV
KSSV 2018년 10월 16일
Are you sure the above code is working?
Yagiz Simsek
Yagiz Simsek 2018년 10월 16일
No, its not working :) That is why asked the question actually. I couldn't figure it out how do I correctly edit it and plot it as I wanted. But if you delete all loop codes its working well for the calculate values.

댓글을 달려면 로그인하십시오.

 채택된 답변

KSSV
KSSV 2018년 10월 16일

1 개 추천

x=[1:0.1:2];
N = length(x) ;
P1 = zeros(N,1) ;
P2 = P1 ;
P3 = P1 ;
for i=1:N
A=[2*x(i),x(i),0;x(i),-6*x(i)^2,0;0,0,5*x(i)] ;
% Calculate Invariants
[V,L]=eig(A) ;
% Principal Values are the Diagonal Elements of the L Matix
P1(i) = abs(L(1,1)) ;
P2(i) = abs(L(2,2)) ;
P3(i) = abs(L(3,3)) ;
end
figure
hold on
plot(x,P1,'.-r') ;
plot(x,P2,'.-b') ;
plot(x,P3,'.-g') ;
legend({'Value 1', 'Value 2', 'Value 3'})

댓글 수: 1

Yagiz Simsek
Yagiz Simsek 2018년 10월 16일
Thank you so much that is realy make sense right now :) Thank you

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

태그

질문:

2018년 10월 16일

댓글:

2018년 10월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by