Define matrix function to output matrix

12 ビュー (過去 30 日間)
M Abo
M Abo 2021 年 11 月 14 日
編集済み: Jan 2021 年 11 月 14 日
Hello
I want to define sqrt function for matrix with f= fumn(A , sqrt) .
But I can not use this form of definition of matrix function for every function such 1/x or exp(-x) , exp(- sqrt(x)),...
I will be grateful offer your suggestions to me.
thank you

回答 (1 件)

Jan
Jan 2021 年 11 月 14 日
編集済み: Jan 2021 年 11 月 14 日
A = rand(3);
fumn(A, @sqrt)
ans = 3×3
0.5456 0.9703 0.9907 0.8551 0.3477 0.4702 0.6054 0.8961 0.8144
fumn(A, @(x) 1 ./ x)
ans = 3×3
3.3599 1.0622 1.0188 1.3676 8.2739 4.5222 2.7286 1.2454 1.5076
fumn(A, @(x) exp(-x))
ans = 3×3
0.7426 0.3901 0.3747 0.4813 0.8862 0.8016 0.6932 0.4480 0.5152
function f = fumn(A, fcn)
f = fcn(A);
end

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by