Operating with DerivativeStructures

I want to create my own Field version of a function that transforms a state in inertial coordinates to curvilinear coordinates (given the reference state of the curvilinear frame as another inertial state). I don’t have much experience with Hipparchus or java, so something that is probably very simple is proving difficult.

For example, one of the first things I have to do is rotate the state of the ‘deputy’ (or chaser) to the frame of the reference orbit. But the components of this state are the field elements from which I want the derivatives at the end (basically a jacobian of the curvilinear transformation, but computed with differential algebra for checking purposses). Normally (in Matlab) I would just do:

    r_dep_ECI   = X(1:3,i);
    v_dep_ECI   = X(4:6,i);

    r_dep_RSW1  = R_RSW1*r_dep_ECI;
    v_dep_RSW1  = R_RSW1*v_dep_ECI;

But with the field elements I guess it should be like:

    r_dep_ECI   = X(1:3,i);
    v_dep_ECI   = X(4:6,i);

    params  = 6; % NUMBER OF PARAMETERS
    % Order of derivation of the DerivativeStructures
    order   = 1;
    factory = DSFactory(params, order);
    x0      = factory.variable(0,r_dep_ECI(1));
    y0      = factory.variable(1,r_dep_ECI(2));
    z0      = factory.variable(2,r_dep_ECI(3));
    xp0     = factory.variable(3,v_dep_ECI(1));
    yp0     = factory.variable(4,v_dep_ECI(2));
    zp0     = factory.variable(5,v_dep_ECI(3));

    % r_dep_ECI = FieldVector3D(x0, y0, z0);
    r_dep_ECI = Array2DRowFieldMatrix([x0; y0; z0]);

    r_dep_RSW1  = R_RSW1.multiply(r_dep_ECI);

Where now the rotation matrix should be something that can accept the vector of derivative structures to linearly combine the columns…

I have yet to find a way to do this simple thing. Some advice?

I have come up with this for the moment:

    QSW_lof = LOFType.QSW;
    Inertial_ToRSW = QSW_lof.rotationFromInertial(PVCoordinates(Vector3D(r),Vector3D(v)));

    r_dep_ECI   = X(1:3,i);
    v_dep_ECI   = X(4:6,i);

    params  = 6; % NUMBER OF PARAMETERS
    % Order of derivation of the DerivativeStructures
    order   = 1;
    factory = DSFactory(params, order);
    x0      = factory.variable(0,r_dep_ECI(1));
    y0      = factory.variable(1,r_dep_ECI(2));
    z0      = factory.variable(2,r_dep_ECI(3));
    xp0     = factory.variable(3,v_dep_ECI(1));
    yp0     = factory.variable(4,v_dep_ECI(2));
    zp0     = factory.variable(5,v_dep_ECI(3));

    F_Inertial_ToRSW1 = FieldRotation(x0.getField(),Inertial_ToRSW);

    r_dep_ECI_F = FieldVector3D(x0, y0, z0);
    v_dep_ECI_F = FieldVector3D(xp0, yp0, zp0);

    r_dep_RSW1 = F_Inertial_ToRSW1.applyTo(r_dep_ECI_F);
    v_dep_RSW1 = F_Inertial_ToRSW1.applyTo(v_dep_ECI_F);  

It seems to work, so I’ll go this way for now.

1 Like

Hi there,

Just a note: if you’re only interested in first order derivatives, you can use the Gradient class which might be a little more light weight.

Best,
Romain

1 Like