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 CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by