Define matrix function to output matrix

17 Ansichten (letzte 30 Tage)
M Abo
M Abo am 14 Nov. 2021
Bearbeitet: Jan am 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

Antworten (1)

Jan
Jan am 14 Nov. 2021
Bearbeitet: Jan am 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

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by