Hello, Its my first day at Matlab and I want to do the following:
I have a 9x9 matrix M(w) that has a variable w. I want to plot the 9 eigenvalues of M(w) (lets call them a_i with i=1,2,...,9) with respect to w. So in the end the graph is showing nine functions a_i(w) i=1,2,...,9.
My Code so far is:
w=(0:0.01:4)*ev/hb;
D_=zeros(9,length(w));
for n=1:length(w)
M=(Here define matrix);
[v,D]=eig(M);
D_(:,n)=diag(D);
end
Plot(hb*w/ev,D_)
Put I dont know how to define M properly such that with each iteration comes a new value for w. I hope someone can help me

 채택된 답변

Torsten
Torsten 2022년 3월 9일

1 개 추천

function main
ev = ...;
hb = ...;
w = (0:0.01:4)*ev/hb;
D_= zeros(9,numel(w));
for n = 1:numel(w)
M = Define_Matrix_M(w(n));
[~,D] = eig(M);
D_(:,n) = diag(D);
end
plot(hb*w/ev,D_)
end
function M = Define_Matrix_M(w)
% Set M depending on w here
end

댓글 수: 3

Alland Kiepert
Alland Kiepert 2022년 3월 10일
편집: Alland Kiepert 2022년 3월 10일
Thanks for the quick reply. I now get the following error:
File: test.m Line: 49 Column: 13
Invalid expression. When calling a function or indexing a variable, use parentheses.
Otherwise, check for mismatched delimiters.
In Line 49 I wrote:
function M =[....
is the syntax here wrong ?
A line similar to
function M =[....
does not appear in my code suggestion.
Oh. Youre right. I interpreted too much in your code

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

질문:

2022년 3월 9일

편집:

2022년 3월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by