function nma_runProbeSimulation %runs simulation of probe starting from some position and velosity vector for some delta time % % runs a simple simulation of a probe starting from some % position and velosity vector for some delta time. % % Author: Nasser Abbasi % April 30, 2003. % change history % name date changes % ----- ----- -------- % nma 050303 add ecc. vector to plot % TRUE=1; FALSE=0; EARTH_CANONICAL=1; ENGLISH=2; METRIC=3; r0_vec = input('Enter initial position vector r0 [DU] >'); v0_vec = input('Enter initial velosity vector v0 [DU/TU] >'); mu = input('Enter mu (gravitational parameter) >'); %plotMode=input('plot mode? [1=show orbit trace, 2=show radial vector] >'); simulationTime = input('How long to run the simulation? [hrs] >'); nSteps=input('number of steps? >'); % support other units later %units=input('Which units? [1=earth canonical, 2=English, 3=Metric] >'); % % covert all to canonical, then flip back at the end if needed % %TC=1; %if(units ~=EARTH_CANONICAL) % switch(units) % case ENGLISH % simulationTime= TC=1.239446309*10^-3; simulationTime = simulationTime*60*60*TC; % CIRCLE % r0_vec=[0 1 .2]; % v0_vec=[.9 0 .123]; % hyparabola? % r0_vec=[0 1.1 0 ]; % v0_vec=[1 0 1.4]; % good ELLIPS on the x-y plane only. nice sim do with no pause %r0_vec=[1.2 0 0]; %v0_vec=[sqrt(2) 0 0] % ELLIPS on the x-y plane only. nice sim do with no pause %r0_vec=[1.2 0 0]; %v0_vec=[.1 1 0]; % ELLIPS on the x-y plane only. nice sim do with no pause % this shows more clearly kepler second law. % use mu=5 to see it better %r0_vec=[1.2 .9 0]; %v0_vec=[.1 1 0]; %50 hrs, 1000 steps ******************* %r0_vec=[1.2 .9 .2]; %v0_vec=[.1 1 0]; % problem 1, Dr Orme given %r0_vec=[0 1.1 0]; %v0_vec=[sqrt(2) 0 0 ]; %fprintf('r0 = %6.6f I + %6.6f J + %6.6f K\n',r0_vec(1),r0_vec(2),r0_vec(3)); %fprintf('v0 = %6.6f I + %6.6f J + %6.6f K\n',v0_vec(1),v0_vec(2),v0_vec(3)); fprintf('\nProbe is moving .....\n\n'); time_ = linspace(0,simulationTime,nSteps); timeStepDuration = time_(2)-time_(1); rx = zeros(length(time_),1); ry = rx; rz = rx; vx = rx; vy = rx; vz = rx; rx(1)=r0_vec(1); ry(1)=r0_vec(2); rz(1)=r0_vec(3); vx(1)=v0_vec(1); vy(1)=v0_vec(2); vz(1)=v0_vec(3); for(i=2:length(time_)-1) [r_vec,v_vec] = nma_moveProbe(r0_vec,v0_vec,timeStepDuration,mu); rx(i)=r_vec(1); ry(i)=r_vec(2); rz(i)=r_vec(3); vx(i)=v_vec(1); vy(i)=v_vec(2); vz(i)=v_vec(3); r0_vec=r_vec; v0_vec=v_vec; end figure; % enable double buffering to reduce flickering. set(gcf,'DoubleBuffer','on') plot3(0,0,0,'*'); hold on; if( abs(min(rx)-max(rx))eps) if(timeThisCycle >= real(o.period) ) timeThisCycle=0; keepPlottingTrace=FALSE; end end end