Question: I have created a large positive definite (thus symmetric) matrix in Matlab. For sake of simplicity, let's assume that the matrix has the following form:

$K= \left[ \begin{array}{ccc} k\_{11} & \cdots & k\_{1n} \\ \vdots & \ddots & \vdots \\
k\_{n1} & \cdots & k\_{nn}\end{array} \right]$.

Now I want to raise it to a power in an elementwise way, let's say to the power of $\lambda$.

Since $K$ is known, while $\lambda$ is unknown and has to be estimated via an optimization routine, I save beforehand the matrix $K$. In the optimization routine I have to compute at each iteration the value of the matrix raised to the power of $\lambda$.

My question is the following: Is there a way to perform this operation in a fast way, by exploiting the properties of the matrix $K$?

What I have done until now:

1st approach: Compute $K^\lambda$ in a straightforward way, that is to say, using command "K.^\lambda" in matlab. 

2nd approach: Use two for loops, where the first one iterates from i=1:n and the second one from j=i:n. This will create an upper diagonal matrix and due to symmetry, I can use triu command to get back the full matrix.

Nonetheless, both approaches are rather time consuming, due to the large size of the matrix. Does anyone have any better idea about how I could perform this operation?

Answer: 
Instead of trying to shoehorn this into an ODE solver you write yourself (that probably uses a simplistic time step length selection method, low order, etc), use one of the existing, advanced and very accurate solvers for ODEs that you can find in any software package -- e.g., `dsolve` in Maple, `NDSolve` in Mathematica, or `ode45` in Matlab. If necessary, play with the parameters these functions have and that you can glean from their respective help pages.

The point being that these are fantastic methods that give you high accuracy you could never get from a method you implement yourself in a finite amount of time. There's no point wasting your time reinventing something others have already done.
My suggestion is to analytically detect the singularities and then to switch form explicit solver to implicit one around the singularity.
From this equation
$
\psi ' = \dfrac{\phi ' + 2 \frac{\phi}{\eta}}{\eta-\phi}\psi.
$
it follows that the singularity is around $\eta-\phi$. Therefore, you should require that 
$
\phi ' = - 2 \frac{\phi}{\eta} 
$
with a solution $\phi=\frac{c}{{\eta}^{2}}$.
Therefore 
$
\eta = \frac{c}{{\eta}^{2}}
$
and the critical values is $\eta^\*= ^3\sqrt{c}$.

The second equation
$
\phi'=\dfrac{\frac{1}{\gamma} f'}{\psi(\eta-\phi)}-\dfrac{3}{2}\dfrac{\phi}{\eta-\phi}
$
will be then
$
 f' = \dfrac{3 \gamma \psi}{2} \phi 
$

The first equation
$
f'=\dfrac{f[-3\eta + (3+\gamma/2)\phi - 2\gamma \dfrac{\phi ^2}{\eta}]}{(\eta-\phi)^2-f/\psi}
$
will become
$
f'=\psi(-3\eta + (3+\gamma/2)\phi - 2\gamma \dfrac{\phi ^2}{\eta}) 
$