First step with matlab


#1

This post was flagged by the community and is temporarily hidden.


#2

Hi,

There used to be a small example on the previous orekit wiki but cannot find that page now. I do not have a matlab license anymore but this below is the example that at some point was on the wiki. At least is shows how the library is interfaced.

Regards
/Petrus

%
% /* Copyright 2002-2018 CS Systèmes d'Information
%  * Licensed to CS Systèmes d'Information (CS) under one or more
%  * contributor license agreements.  See the NOTICE file distributed with
%  * this work for additional information regarding copyright ownership.
%  * CS licenses this file to You under the Apache License, Version 2.0
%  * (the "License"); you may not use this file except in compliance with
%  * the License.  You may obtain a copy of the License at
%  *
%  *   http://www.apache.org/licenses/LICENSE-2.0
%  *
%  * Unless required by applicable law or agreed to in writing, software
%  * distributed under the License is distributed on an "AS IS" BASIS,
%  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%  * See the License for the specific language governing permissions and
%  * limitations under the License.
%  */
%
% Translated from SlaveMode.java to Matlab by Petrus Hyvönen 2011 as an
% example of how to access orekit from matlab
% the jars orekit-8.0.jar, hipparchus-core-1.0.jar, hipparchus-geometry-1.0.jar,
% hipparchus-ode-1.0.jar, hipparchus-fitting-1.0.jar, hipparchus-optim-1.0.jar
% and orekit-data.zip is in current matlab dir.


______
% These seems to work if pasted to prompt.
javaaddpath 'C:\ ... enter your path here ...\MATLAB'
javaaddpath 'C:\.. enter your path here ...\MATLAB\orekit-8.0.jar'
javaaddpath 'C:\.. enter your path here ...\\MATLAB\hipparchus-core-1.0.jar
javaaddpath 'C:\.. enter your path here ...\\MATLAB\hipparchus-geometry-1.0.jar
javaaddpath 'C:\.. enter your path here ...\\MATLAB\hipparchus-ode-1.0.jar
javaaddpath 'C:\.. enter your path here ...\\MATLAB\hipparchus-fitting-1.0.jar
javaaddpath 'C:\.. enter your path here ...\\MATLAB\hipparchus-optim-1.0.jar


%% do the imports
import org.orekit.errors.OrekitException
import org.orekit.frames.Frame
import org.orekit.frames.FramesFactory
import org.orekit.orbits.KeplerianOrbit
import org.orekit.orbits.Orbit
import org.orekit.orbits.PositionAngle
import org.orekit.propagation.SpacecraftState
import org.orekit.propagation.analytical.KeplerianPropagator
import org.orekit.data.DataProvidersManager
import org.orekit.data.ZipJarCrawler
import org.orekit.time.AbsoluteDate
import org.orekit.time.TimeScalesFactory

%% Configure Orekit. The file orekit-data.zip must be in current dir
DM=org.orekit.data.DataProvidersManager.getInstance()
crawler=org.orekit.data.ZipJarCrawler('orekit-data.zip')
DM.clearProviders()
DM.addProvider(crawler)

%% Initial orbit parameters
a = 24396159;    % semi major axis in meters
e = 0.72831215;  % eccentricity
i = (7.0)/180*pi; % inclination
omega = (180)/180*pi; % perigee argument
raan = (261)/180*pi; %right ascension of ascending node
lM = 0.0; % mean anomaly

%% Set inertial frame
inertialFrame = FramesFactory.getEME2000()

%% Initial date in UTC time scale
utc = TimeScalesFactory.getUTC();
initialDate = AbsoluteDate(2004, 01, 01, 23, 30, 00.000, utc)

%% Setup orbit propagator
%gravitation coefficient
mu =  3.986004415e+14

%Orbit construction as Keplerian
initialOrbit = KeplerianOrbit(a, e, i, omega, raan, lM, PositionAngle.MEAN, inertialFrame, initialDate, mu)

%Simple extrapolation with Keplerian motion
kepler = KeplerianPropagator(initialOrbit);

%Set the propagator to slave mode (could be omitted as it is the default mode)
kepler.setSlaveMode()

%% Setup propagation time
%Overall duration in seconds for extrapolation
duration = 180*60.0

%Stop date
finalDate =  AbsoluteDate(initialDate, duration, utc)

%Step duration in seconds
stepT = 30.0

%% Perform propagation
%Extrapolation loop
cpt = 1;
extrapDate = initialDate
while extrapDate.compareTo(finalDate) <= 0
    currentState = kepler.propagate(extrapDate);
    fprintf('step %d: time %s %s\n', cpt, char(currentState.getDate()), char(currentState.getOrbit()))
    coord=currentState.getPVCoordinates.getPosition;
    P(:,cpt)=[coord.getX coord.getY coord.getZ]';
    extrapDate = AbsoluteDate(extrapDate, stepT, utc);
    cpt=cpt+1;
end
%%
figure;
plot3(P(1,:),P(2,:),P(3,:));

#3

Hi Petrus,

I don’t know why this example has not been migrated with the others. I temporarily disabled the redirection in Apache server to allow access to the wiki of our old forge. The example you are looking for is here:

https://www.orekit.org/forge/projects/orekit/wiki/Integration_in_Matlab

Regards,

Sébastien


#4

Thanks a lot for this example.

I still have a problem to run this script, the command window return me :

Undefined variable “org” or class “org.orekit.data.DataProvidersManager.getInstance”.
Error in PropagationDistribution (line 19)
DM=org.orekit.data.DataProvidersManager.getInstance()

Have got any idea to solve this issue ?

Thanks


listed #5

#6

Hi @Tintin

What version of Orekit do you use ? To my mind, your problem is that you don’t use a correct version of Java on your Matlab interface.

You shall use, at least, Java 8 to run correctly Orekit on your Matlab interface (if your version of Orekit is greater than 8.0).

To check your version of Java, on your Matlab terminal write : version -java

In the case of your Java version is lower than 8, download the correct jdk version and follow the recommendations on the Mathworks website depending if you are using Linux or Windows.

Best regards,

Bryan