Seeking guidance on how to do programming for function and matrix
古いコメントを表示
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!
回答 (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 件のコメント
Marisol Riddell
2016 年 11 月 17 日
Clearly, you're not using R2016b. As I wrote:
result = bsxfun(@minus, bsxfun(@times, a, c), b.^2);
カテゴリ
ヘルプ センター および File Exchange で Common Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!