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 comentarios

KSSV
KSSV el 16 de Oct. de 2018
Are you sure the above code is working?
Yagiz Simsek
Yagiz Simsek el 16 de Oct. de 2018
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.

Iniciar sesión para comentar.

 Respuesta aceptada

KSSV
KSSV el 16 de Oct. de 2018
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 comentario

Yagiz Simsek
Yagiz Simsek el 16 de Oct. de 2018
Thank you so much that is realy make sense right now :) Thank you

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Numerical Integration and Differential Equations en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 16 de Oct. de 2018

Comentada:

el 16 de Oct. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by