You can Map
F
on s
:
DiagonalMatrix[F /@ s] // MatrixForm // TeXForm
$\left(
\begin{array}{ccccc}
-7.52954 & 0. & 0. & 0. & 0. \\
0. & -7.07789 & 0. & 0. & 0. \\
0. & 0. & -6.64467 & 0. & 0. \\
0. & 0. & 0. & -6.2295 & 0. \\
0. & 0. & 0. & 0. & -5.832 \\
\end{array}
\right)$
Or give the function F
the Attribute
Listable
and use F@s
:
ClearAll[F]
F[s_] := Piecewise[{{s^3, s <= 5}, {s^2, s > 5}}];
SetAttributes[F, Listable]
DiagonalMatrix[F @ s] // MatrixForm // TeXForm
$\left(
\begin{array}{ccccc}
-7.52954 & 0. & 0. & 0. & 0. \\
0. & -7.07789 & 0. & 0. & 0. \\
0. & 0. & -6.64467 & 0. & 0. \\
0. & 0. & 0. & -6.2295 & 0. \\
0. & 0. & 0. & 0. & -5.832 \\
\end{array}
\right)$
DiagonalMatrix[F /@ s]
$\endgroup$Attributes[F] = Listable
. $\endgroup$