Define matrix function to output matrix

16 visualizaciones (últimos 30 días)
M Abo
M Abo el 14 de Nov. de 2021
Editada: Jan el 14 de Nov. de 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

Respuestas (1)

Jan
Jan el 14 de Nov. de 2021
Editada: Jan el 14 de Nov. de 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

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by