How to apply exponential anonymous function to NxN matrices?

1 回表示 (過去 30 日間)
Kris Hoffman
Kris Hoffman 2020 年 11 月 12 日
コメント済み: Star Strider 2020 年 11 月 12 日
I have 2 NxN matrices (a and b) that I need to perform an operation on. Ideally I'd like to use an anonymous function to compute this elementwise all at once.
So far I have,
syms t
a = rand(32,32);
b = rand(32,32);
Y = @(a,b) a.*exp(-t./b);
Test = integral(Y(a,b),0,3);

採用された回答

Star Strider
Star Strider 2020 年 11 月 12 日
The symbolic involvement is not necessary.
Try this:
a = rand(32,32);
b = rand(32,32);
Y = @(a,b,t) a.*exp(-t./b);
Test = integral(@(t)Y(a,b,t),0,3, 'ArrayValued',1);
Tha 'ArrayValued' name-value pair is important here.
  2 件のコメント
Kris Hoffman
Kris Hoffman 2020 年 11 月 12 日
Ah. ok! Perfect!
Star Strider
Star Strider 2020 年 11 月 12 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParticle & Nuclear Physics についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by