Hello,
I am currently attempting to reproduce the FieldPropagation tutorial in Matlab to better understand how to run Monte Carlo simulations with Orekit. I have not used lambda expressions or the “->” arrow operator in Java before, so I am wondering if someone can help me understand better what is happening in the piece of code below and, if possible, how I might rewrite this particular section of code with Matlab syntax since that is where I need to be able to use this code for the moment.
Thank you,
Erin

//calculate and print the error on every fixed step on the file error.txt
//we defined the StepHandler to do that giving him the random number generator,
//the size of the montecarlo simulation and the initial date
numProp.getMultiplexer().add(zero.add(int_step),
currentState → {
final TimeStampedFieldPVCoordinates PV_t =
(TimeStampedFieldPVCoordinates) currentState.getPVCoordinates();…

I may have thought of a better way to ask this question:
I see that currentState is using in the execution of the block of code that comes after the arrow (inside the braces { }). But where is currentState itself defined, or how should I define it in Matlab?
Thanks again,
Erin

This lambda function is a shortcut to designing a dedicated step handler class.
The canonical Java way to do it would be: numProp.getMultiplexer().add(zero.add(int_step), new MyStepHandler());
Where, in another file, you define the class MyStepHandler:

public class MyStepHandler<T extends CalculusFieldElement<T>> implements FieldOrekitFixedStepHandler<T> {
@Override
public void handleStep(FieldSpacecraftState<T> currentState) {
final TimeStampedFieldPVCoordinates PV_t =
(TimeStampedFieldPVCoordinates) currentState.getPVCoordinates();
// etc.
}
}

I think you’ll have to do it the classical way with Matlab (i.e. subclassing).

Lambda functions are anonymous functions. In Matlab you create them using @(var) func. Depending on the complexity of the anonymous function you can define them in line (e.g. for very simple functions like @(x,y) x^2 + y^3 - x*sin(y)) or as a “normal” function (e.g. function [out] = func(in1, in2, in3)) and then transforming it into an anonymous one as @(in1) func(in1, in2, in3). The second way is for example used if you want to perform an optimization on a function that has a lot of code to run through. In your case you probably need to use the second example (even though I’m not sure if the Orekit wrapper for Matlab supports this, I’ve never used it).