Define matrix function to output matrix

2 views (last 30 days)
M Abo
M Abo on 14 Nov 2021
Edited: Jan on 14 Nov 2021
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

Answers (1)

Jan
Jan on 14 Nov 2021
Edited: Jan on 14 Nov 2021
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

Categories

Find more on Data Types in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!