Seeking guidance on how to do programming for function and matrix
Mostrar comentarios más antiguos
How do I program ac-b^2, given that a and c are both all numbers from 1 to 10 and b is all numbers from -10 to 10? I have been searching hours for an answer. I finally did it long hand and got 986 possible matrix combinations for [a b;b c] that fit. I was introduced to Matlab for the very first time about 3 weeks ago, so I am woefully undereducated on it. Any assistance is appreciated. Thanks!
Respuestas (1)
I assume all numbers from 1 to 10 actually means all integers from 1 to 10, otherwise there's an infinity of numbers...
In R2016b, it's dead easy to get all combinations. Simply have all vectors along different dimension and implicit expansion will take care of the rest:
a = 1:10; %vector along 1st dimension (row vector)
b = (-10:10).'; %vector along 2nd dimension (column vector)
c = permute(1:10, [1 3 2]); %vector along 3rd dimension
result = a.*c - b.^2
result = bsxfun(@minus, bsxfun(@times, a, c), b.^2);
2 comentarios
Marisol Riddell
el 17 de Nov. de 2016
Clearly, you're not using R2016b. As I wrote:
result = bsxfun(@minus, bsxfun(@times, a, c), b.^2);
Categorías
Más información sobre Common Operations 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!