What would be a Matlab function with two arguments that returns a Matrix (as shown) ?
Mostrar comentarios más antiguos
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 comentarios
Image Analyst
el 10 de Dic. de 2017
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
el 10 de Dic. de 2017
Editada: Walter Roberson
el 10 de Dic. de 2017
Respuesta aceptada
Más respuestas (2)
Roger Stafford
el 16 de Dic. de 2017
@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 comentarios
Roger Stafford
el 16 de Dic. de 2017
@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
el 16 de Dic. de 2017
Salaijobhaka
el 11 de Dic. de 2017
Editada: Salaijobhaka
el 11 de Dic. de 2017
Categorías
Más información sobre Univariate Discrete Distributions en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!