Plotting a function of determinant values vs n values.

10 ビュー (過去 30 日間)
Odom Seng
Odom Seng 2016 年 6 月 30 日
編集済み: José-Luis 2016 年 7 月 1 日
Hi, so I have a function s(n), that spits out a n*n matrix. What I want to do is plot the determinant of each s(n) matrix that my s function makes and plot it against n from 1 to 32. I think I have to make a for loop, but I'm not entirely sure how to go about it.
Here's my code for the s function:
if true
% code
function[output]=s(n)
output=zeros(n);
for i = 1:n
for j=1:n
output(i,j)=sqrt(2./n)*sin((pi*(i-.5)*(j-.5))./n);
end
end
end
end

回答 (3 件)

KSSV
KSSV 2016 年 7 月 1 日
編集済み: KSSV 2016 年 7 月 1 日
I didn't get your question exactly. I understand the following:
You want to display the output of the above function s.
For a given n the above function gives output a matrix of size nXn. As it is a matrix, you can view it using surf, pcolor.
Eg.
K = s(100) ;
surf(K) ; shading interp ;
pcolor(K) ; shading interp ;

Torsten
Torsten 2016 年 7 月 1 日
for k=1:32
index(k) = k;
output = s(k);
determinant(k) = det(output);
end
plot(index,determinant)
Best wishes
Torsten.

José-Luis
José-Luis 2016 年 7 月 1 日
編集済み: José-Luis 2016 年 7 月 1 日
I'm on a one liner spree, and you don't actually need those loops:
myFun = @(x) det(bsxfun(@(ii,jj) sqrt(2./n)*sin((pi*(ii-.5)*(jj-.5))./n),1:x,(1:x)'));
fplot(myFun,[1 32])

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by