What would be a Matlab function with two arguments that returns a Matrix (as shown) ?
古いコメントを表示
I would like to create a Matlab function (with two arguments, N = Number of parameter, PO = polynomial order) that returns a matrix as shown in the linked file. Desired output Matrix
3 件のコメント
Image Analyst
2017 年 12 月 10 日
I have no idea what those matrices are. It looks vaguely similar to meshgrid output, but it's not. I imagine, from the names of things it might have something to do with polyfit() and polyval(), but I can't figure it out. There is obviously some information missing, either you didn't tell us, or your instructor didn't tell you. So you either get it, or start guessing and trying to figure it out.
Salaijobhaka
2017 年 12 月 10 日
編集済み: Walter Roberson
2017 年 12 月 10 日
採用された回答
その他の回答 (2 件)
Roger Stafford
2017 年 12 月 16 日
@Salaijobhaka: I finally managed to write the script I mentioned earlier in the comment above. It produces the same ordering as you described in your "Desired output Matrix" file five days ago. It wasn't quite as simple as I thought it would be. It makes important use of the 'cumsum' function for appropriate addressing. The 'round' function is supposed to help protect against round-off errors for very large numbers of rows in the resulting matrix, M.
PO = 4; N = 7; % <-- Choose PO and N
M = zeros(round(prod(N+(1:PO))/prod(1:PO)),PO);
c = 1:N+1;
M(1:N+1,1) = (0:N)';
for ip = 2:PO
s2 = repmat(c(N+1),1,N+1);
s1 = c(N+1)-[0,c(2:N+1)-1];
c = cumsum(c);
d2 = c(N+1)-[0,c(1:N)];
d1 = [d2(2:N+1)+1,1];
for in = 1:N+1
M(d1(in):d2(in),3:ip) = M(s1(in):s2(in),2:ip-1);
M(d1(in):d2(in),2) = M(s1(in):s2(in),1)-M(s1(in),1);
M(d1(in):d2(in),1) = repmat(M(s1(in)),d2(in)-d1(in)+1,1);
end
end
2 件のコメント
Roger Stafford
2017 年 12 月 16 日
@Salaijobhaka: Note: I see that unfortunately I have inadvertently interchanged N and PO, so that my N is your PO and my PO is your N, as you have defined them in your comment. I will leave the task of reversing these two variables in the script to you, since I am rather sleepy at the present moment and might make a mistake in that undertaking.
Salaijobhaka
2017 年 12 月 16 日
Salaijobhaka
2017 年 12 月 11 日
編集済み: Salaijobhaka
2017 年 12 月 11 日
カテゴリ
ヘルプ センター および File Exchange で Univariate Discrete Distributions についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!