Ok,
there's a lot more not in order.
In your function f.trial there's a big For-loop, with i as a running variable.
Within that For-loop you have twice an assigment to a variable called J where the rhs is a comnpound statement. In that compound statement there's another nested set of For-loops using j and also (again) i as running variables. That is a guarantee for interference with the outer For-loop. So you are definitely not getting what you hoped to get, or you must be very lucky.
Also, that the nested for loop runs on both i and j, but does not use them, there is nothing within the inner For-loop that depends on either i or j. It repeats the VERY same statement (assigning something to the first two columns of J) over and over again. So this too is doing something other than what you intended.
A minor improvement can be achieved: in between the two assignments to J there's an IF statement with an Otherwise. Inside the Otherwise you unnecessarily assign alpha to alpha and beta to beta, while you (probably) only need to double lambda.
I've stopped looking further.
We may be able to help you if you explain what the problem is you are trying to solve with this function. It would surely help to break it apart in multiple functions, where one function calls another {I think that the assignment to J could be done with a separate function that you then call twice. And I would set the now embedded function L.2(J) apart.}. That way the functionality of each part can be tested easily, and the f.trial becomes smaller for better overview.
Success!
Luc