function nma_rocket_design_PERMUTE() %helper function for rocket design project, UCI g=9.80666; startIsp = 200; endIsp = 400; Isp=linspace(startIsp,endIsp,(endIsp-startIsp+1)/10); startEpsilon = 0.1; endEpsilon = 0.3; epsilon=linspace(startEpsilon,endEpsilon,endEpsilon*100-startEpsilon*100+1); %21 different values Ve=zeros(length(Isp),1); for(i=1:length(Isp)) Ve(i)=Isp(i)*g/1000; % in km/sec end deltaV=0.02868; % km/sec, from design project I. last step mL=250; minTotalMass = Inf; bestVe = 0; bestEpsilon = 0; bestZ = 0; bestLambda = 0; bestMp = 0; bestMs = 0; %one stage only for this step for(i=1:length(Ve)) for(j=1:length(epsilon)) try lagrange = nma_rocket_getLagrangeMultiplier(deltaV,Ve(i),epsilon(j)); [Z,mp,ms,lambda]=nma_rocket_mutliStageSolutionLagrange(lagrange,Ve(i),epsilon(j),mL); totalMass=sum(mp)+sum(ms)+mL; if( totalMass <= minTotalMass) % fprintf('totalMass=%f, j=%d, i=%d\n',totalMass,j,i); minTotalMass = totalMass; bestVe = Ve(i); bestEpsilon = epsilon(j); bestZ = Z; bestLambda = lambda; bestMp = mp; bestMs = ms; end catch end end end fprintf('*********** from 2nd satellite to final position **********\n'); if(minTotalMass>0) fprintf('deltaV=%f\n',deltaV); fprintf('min total mass=%f kg\n',minTotalMass); fprintf('m0 = %f kg\n',mL+bestMp+bestMs); fprintf('mf = %f kg\n',mL+bestMs); fprintf('best Ve=%f km/sec \n',bestVe); fprintf('best Isp=%f sec\n',bestVe/g * 1000); fprintf('best Epsilon=%f \n',bestEpsilon); fprintf('best Z =%f \n',bestZ); fprintf('best lambda=%f \n',bestLambda); fprintf('best mp =%f \n',bestMp); fprintf('best ms =%f \n',bestMs); else fprintf('Failed to find any one stage that will meet deltaV with given Isp\n'); fprintf('Please increase number of stages of increase Isp or reduce payload\n'); end %step before last. Use same rocket engine found above since no staging deltaV=0.255; % km/sec, from design project I. last step mL=250+100+bestMp+bestMs; lagrange = nma_rocket_getLagrangeMultiplier(deltaV,bestVe,bestEpsilon); [Z,mp,ms,lambda]=nma_rocket_mutliStageSolutionLagrange(lagrange,bestVe,bestEpsilon,mL); fprintf('********* from 1st satellite to second satellite\n'); fprintf('deltaV=%f\n',deltaV); fprintf('m0 = %f kg\n',mL+mp+ms); fprintf('mf = %f kg\n',mL+ms); fprintf('mp=%f \n',mp); fprintf('ms=%f \n',ms); fprintf('lambda=%f \n',lambda); fprintf('Z=%f \n',Z); fprintf('Ve=%f \n',bestVe); fprintf('Isp=%f \n',bestVe/g*1000); fprintf('epsilon=%f\n',bestEpsilon); %step before that. use same rocket engine. deltaV=0.0598; % km/sec, from design project I. last step mL=mL+mp-100+ms; %remove the 100 kg lagrange = nma_rocket_getLagrangeMultiplier(deltaV,bestVe,bestEpsilon); [Z,mp,ms,lambda]=nma_rocket_mutliStageSolutionLagrange(lagrange,bestVe,bestEpsilon,mL); fprintf('********* from Geo arrival to second satellite\n'); fprintf('deltaV=%f\n',deltaV); fprintf('m0 = %f kg\n',mL+mp+ms); fprintf('mf = %f kg\n',mL+ms); fprintf('mp=%f \n',mp); fprintf('ms=%f \n',ms); fprintf('lambda=%f \n',lambda); fprintf('Z=%f \n',Z); fprintf('Ve=%f \n',bestVe); fprintf('Isp=%f \n',bestVe/g*1000); fprintf('epsilon=%f\n',bestEpsilon); minTotalMass = Inf; bestVe = 0; bestEpsilon = 0; bestZ = 0; bestLambda = 0; bestMp = 0; bestMs = 0; mL=mL+mp+ms; %now the LEO to GEO trip. Try 1 and 2 and 3 stages stages startIsp = 200; endIsp = 400; Isp=linspace(startIsp,endIsp,(endIsp-startIsp+1)/10); %151 different values %one stage try deltaV=4.0716; % km/sec, from design project I. last step for(i=1:length(Ve)) for(j=1:length(epsilon)) try lagrange = nma_rocket_getLagrangeMultiplier(deltaV,Ve(i),epsilon(j)); [Z,mp,ms,lambda]=nma_rocket_mutliStageSolutionLagrange(lagrange,Ve(i),epsilon(j),mL); totalMass=sum(mp)+sum(ms)+mL; if( totalMass <= minTotalMass) %fprintf('totalMass=%f, j=%d, i=%d\n',totalMass,j,i); minTotalMass = totalMass; bestVe = Ve(i); bestEpsilon = epsilon(j); bestZ = Z; bestLambda = lambda; bestMp = mp; bestMs = ms; end catch end end end fprintf('*********** LEO to GEO result with one stage **********\n'); if(minTotalMass>0) fprintf('deltaV=%f\n',deltaV); fprintf('min total mass=%f kg\n',minTotalMass); fprintf('m0 = %f kg\n',mL+bestMp+bestMs); fprintf('mf = %f kg\n',mL+bestMs); fprintf('best Ve=%f km/sec \n',bestVe); fprintf('best Isp=%f sec\n',bestVe/g * 1000); fprintf('best Epsilon=%f \n',bestEpsilon); fprintf('best Z =%f \n',bestZ); fprintf('best lambda=%f \n',bestLambda); fprintf('best mp =%f \n',bestMp); fprintf('best ms =%f \n',bestMs); else fprintf('Failed to find any one stage that will meet deltaV with given Isp\n'); fprintf('Please increase number of stages of increase Isp or reduce payload\n'); end %try 2 stages minTotalMass = Inf; bestVe = []; bestEpsilon = []; bestZ = []; bestLambda = []; bestMp = []; bestMs = []; for(j=1:length(epsilon)) firstStageEps=epsilon(j); secondStageEps=epsilon(j); for(i=1:length(Ve)) firstStageVe=Ve(i); for(k=1:length(Ve)) secondStageVe=Ve(k); try lagrange = nma_rocket_getLagrangeMultiplier(... deltaV,[firstStageVe secondStageVe],[firstStageEps secondStageEps]); [Z,mp,ms,lambda]=nma_rocket_mutliStageSolutionLagrange(... lagrange,[firstStageVe secondStageVe],[firstStageEps secondStageEps],mL); totalMass=sum(mp)+sum(ms)+mL; if( totalMass <= minTotalMass) minTotalMass = totalMass; bestVe(1) = firstStageVe; bestVe(2) = secondStageVe; bestEpsilon(1) = firstStageEps; bestEpsilon(2) = secondStageEps; bestZ = Z; bestLambda = lambda; bestMp = mp; bestMs = ms; end catch end end end end fprintf('*********** LEO to GEO with 2 stages **********\n'); if(minTotalMass>0) fprintf('deltaV=%f\n',deltaV); fprintf('min total mass=%f kg\n',minTotalMass); fprintf('m0 first stage= %f kg\n',mL+bestMp(1)+bestMp(2)+bestMs(1)+bestMs(2)); fprintf('mf first stage= %f kg\n',mL+bestMp(2)+bestMs(1)+bestMs(2)); fprintf('m0 second stage= %f kg\n',mL+bestMp(2)+bestMs(2)); fprintf('mf second stage= %f kg\n',mL+bestMs(2)); fprintf('best Ve first Stage=%f km/sec \n',bestVe(1)); fprintf('best Ve second Stage=%f km/sec \n',bestVe(2)); fprintf('best Isp first stage=%f sec\n',bestVe(1)/g * 1000); fprintf('best Isp second stage=%f sec\n',bestVe(2)/g * 1000); fprintf('best Epsilon first stage=%f \n',bestEpsilon(1)); fprintf('best Epsilon second stage=%f \n',bestEpsilon(2)); fprintf('best Z first stage=%f \n',bestZ(1)); fprintf('best Z second stage=%f \n',bestZ(2)); fprintf('best lambda first stage=%f \n',bestLambda(1)); fprintf('best lambda second stage=%f \n',bestLambda(2)); fprintf('best mp first stage =%f \n',bestMp(1)); fprintf('best mp second stage =%f \n',bestMp(2)); fprintf('best ms first stage =%f \n',bestMs(1)); fprintf('best ms second stage =%f \n',bestMs(2)); else fprintf('Failed to find any one stage that will meet deltaV with given Isp\n'); fprintf('Please increase number of stages of increase Isp or reduce payload\n'); end secondStageM0= minTotalMass; %try 3 stages minTotalMass = Inf; bestVe = []; bestEpsilon = []; bestZ = []; bestLambda = []; bestMp = []; bestMs = []; for(j=1:length(epsilon)) firstStageEps=epsilon(j); secondStageEps=epsilon(j); thirdStageEps=epsilon(j); for(i=1:length(Ve)) firstStageVe=Ve(i); for(k=1:length(Ve)) secondStageVe=Ve(k); for(U=1:length(Ve)) thirdStageVe=Ve(k); try lagrange = nma_rocket_getLagrangeMultiplier(... deltaV,[firstStageVe secondStageVe thirdStageVe],... [firstStageEps secondStageEps thirdStageEps]); [Z,mp,ms,lambda]=nma_rocket_mutliStageSolutionLagrange(... lagrange,[firstStageVe secondStageVe thirdStageVe],... [firstStageEps secondStageEps thirdStageEps],mL); totalMass=sum(mp)+sum(ms)+mL; if( totalMass <= minTotalMass) minTotalMass = totalMass; bestVe(1) = firstStageVe; bestVe(2) = secondStageVe; bestVe(3) = thirdStageVe; bestEpsilon(1) = firstStageEps; bestEpsilon(2) = secondStageEps; bestEpsilon(3) = thirdStageEps; bestZ = Z; bestLambda = lambda; bestMp = mp; bestMs = ms; end catch end end end end end fprintf('*********** LEO to GEO with 3 stages **********\n'); if(minTotalMass>0) fprintf('deltaV=%f\n',deltaV); fprintf('min total mass=%f kg\n',minTotalMass); fprintf('m0 first stage= %f kg\n',mL+bestMp(1)+bestMp(2)+bestMp(3)+... bestMs(1)+bestMs(2)+bestMs(3)); fprintf('mf first stage= %f kg\n',mL+bestMp(3)+bestMp(2)+bestMs(1)+bestMs(2)+bestMs(3)); fprintf('m0 second stage= %f kg\n',mL+bestMp(2)+bestMp(3)+bestMs(2)+bestMs(3)); fprintf('mf second stage= %f kg\n',mL+bestMs(2)+bestMs(3)+bestMp(3)); fprintf('m0 third stage= %f kg\n',mL+bestMp(3)+bestMs(3)); fprintf('mf third stage= %f kg\n',mL+bestMs(3)); fprintf('best Ve first Stage=%f km/sec \n',bestVe(1)); fprintf('best Ve second Stage=%f km/sec \n',bestVe(2)); fprintf('best Ve third Stage=%f km/sec \n',bestVe(3)); fprintf('best Isp first stage=%f sec\n',bestVe(1)/g * 1000); fprintf('best Isp second stage=%f sec\n',bestVe(2)/g * 1000); fprintf('best Isp third stage=%f sec\n',bestVe(3)/g * 1000); fprintf('best Epsilon first stage=%f \n',bestEpsilon(1)); fprintf('best Epsilon second stage=%f \n',bestEpsilon(2)); fprintf('best Epsilon third stage=%f \n',bestEpsilon(3)); fprintf('best Z first stage=%f \n',bestZ(1)); fprintf('best Z second stage=%f \n',bestZ(2)); fprintf('best Z third stage=%f \n',bestZ(3)); fprintf('best lambda first stage=%f \n',bestLambda(1)); fprintf('best lambda second stage=%f \n',bestLambda(2)); fprintf('best lambda third stage=%f \n',bestLambda(3)); fprintf('best mp first stage =%f \n',bestMp(1)); fprintf('best mp second stage =%f \n',bestMp(2)); fprintf('best mp third stage =%f \n',bestMp(3)); fprintf('best ms first stage =%f \n',bestMs(1)); fprintf('best ms second stage =%f \n',bestMs(2)); fprintf('best ms third stage =%f \n',bestMs(3)); else fprintf('Failed to find any one stage that will meet deltaV with given Isp\n'); fprintf('Please increase number of stages of increase Isp or reduce payload\n'); end mL=secondStageM0; minTotalMass = Inf; bestVe = []; bestEpsilon = []; bestZ = []; bestLambda = []; bestMp = []; bestMs = []; %one stage try deltaV=9.412; % km/sec, from design project I. last step for(i=1:length(Ve)) for(j=1:length(epsilon)) try lagrange = nma_rocket_getLagrangeMultiplier(deltaV,Ve(i),epsilon(j)); [Z,mp,ms,lambda]=nma_rocket_mutliStageSolutionLagrange(lagrange,Ve(i),epsilon(j),mL); totalMass=sum(mp)+sum(ms)+mL; if( totalMass <= minTotalMass) %fprintf('totalMass=%f, j=%d, i=%d\n',totalMass,j,i); minTotalMass = totalMass; bestVe = Ve(i); bestEpsilon = epsilon(j); bestZ = Z; bestLambda = lambda; bestMp = mp; bestMs = ms; end catch end end end fprintf('*********** earth to LEO result with one stage **********\n'); if(minTotalMass>0) fprintf('deltaV=%f\n',deltaV); fprintf('min total mass=%f kg\n',minTotalMass); fprintf('m0 = %f kg\n',mL+bestMp+bestMs); fprintf('mf = %f kg\n',mL+bestMs); fprintf('best Ve=%f km/sec \n',bestVe); fprintf('best Isp=%f sec\n',bestVe/g * 1000); fprintf('best Epsilon=%f \n',bestEpsilon); fprintf('best Z =%f \n',bestZ); fprintf('best lambda=%f \n',bestLambda); fprintf('best mp =%f \n',bestMp); fprintf('best ms =%f \n',bestMs); else fprintf('Failed to find any one stage that will meet deltaV with given Isp\n'); fprintf('Please increase number of stages of increase Isp or reduce payload\n'); end %try 2 stages minTotalMass = Inf; bestVe = []; bestEpsilon = []; bestZ = []; bestLambda = []; bestMp = []; bestMs = []; for(j=1:length(epsilon)) firstStageEps=epsilon(j); secondStageEps=epsilon(j); for(i=1:length(Ve)) firstStageVe=Ve(i); for(k=1:length(Ve)) secondStageVe=Ve(k); try lagrange = nma_rocket_getLagrangeMultiplier(... deltaV,[firstStageVe secondStageVe],[firstStageEps secondStageEps]); [Z,mp,ms,lambda]=nma_rocket_mutliStageSolutionLagrange(... lagrange,[firstStageVe secondStageVe],[firstStageEps secondStageEps],mL); totalMass=sum(mp)+sum(ms)+mL; if( totalMass <= minTotalMass) minTotalMass = totalMass; bestVe(1) = firstStageVe; bestVe(2) = secondStageVe; bestEpsilon(1) = firstStageEps; bestEpsilon(2) = secondStageEps; bestZ = Z; bestLambda = lambda; bestMp = mp; bestMs = ms; end catch end end end end fprintf('*********** earth to LEO with 2 stages **********\n'); if(minTotalMass>0) fprintf('deltaV=%f\n',deltaV); fprintf('min total mass=%f kg\n',minTotalMass); fprintf('m0 first stage= %f kg\n',mL+bestMp(1)+bestMp(2)+bestMs(1)+bestMs(2)); fprintf('mf first stage= %f kg\n',mL+bestMp(2)+bestMs(1)+bestMs(2)); fprintf('m0 second stage= %f kg\n',mL+bestMp(2)+bestMs(2)); fprintf('mf second stage= %f kg\n',mL+bestMs(2)); fprintf('best Ve first Stage=%f km/sec \n',bestVe(1)); fprintf('best Ve second Stage=%f km/sec \n',bestVe(2)); fprintf('best Isp first stage=%f sec\n',bestVe(1)/g * 1000); fprintf('best Isp second stage=%f sec\n',bestVe(2)/g * 1000); fprintf('best Epsilon first stage=%f \n',bestEpsilon(1)); fprintf('best Epsilon second stage=%f \n',bestEpsilon(2)); fprintf('best Z first stage=%f \n',bestZ(1)); fprintf('best Z second stage=%f \n',bestZ(2)); fprintf('best lambda first stage=%f \n',bestLambda(1)); fprintf('best lambda second stage=%f \n',bestLambda(2)); fprintf('best mp first stage =%f \n',bestMp(1)); fprintf('best mp second stage =%f \n',bestMp(2)); fprintf('best ms first stage =%f \n',bestMs(1)); fprintf('best ms second stage =%f \n',bestMs(2)); else fprintf('Failed to find any one stage that will meet deltaV with given Isp\n'); fprintf('Please increase number of stages of increase Isp or reduce payload\n'); end %try 3 stages minTotalMass = Inf; bestVe = []; bestEpsilon = []; bestZ = []; bestLambda = []; bestMp = []; bestMs = []; for(j=1:length(epsilon)) firstStageEps=epsilon(j); secondStageEps=epsilon(j); thirdStageEps=epsilon(j); for(i=1:length(Ve)) firstStageVe=Ve(i); for(k=1:length(Ve)) secondStageVe=Ve(k); for(U=1:length(Ve)) thirdStageVe=Ve(k); try lagrange = nma_rocket_getLagrangeMultiplier(... deltaV,[firstStageVe secondStageVe thirdStageVe],... [firstStageEps secondStageEps thirdStageEps]); [Z,mp,ms,lambda]=nma_rocket_mutliStageSolutionLagrange(... lagrange,[firstStageVe secondStageVe thirdStageVe],... [firstStageEps secondStageEps thirdStageEps],mL); totalMass=sum(mp)+sum(ms)+mL; if( totalMass <= minTotalMass) minTotalMass = totalMass; bestVe(1) = firstStageVe; bestVe(2) = secondStageVe; bestVe(3) = thirdStageVe; bestEpsilon(1) = firstStageEps; bestEpsilon(2) = secondStageEps; bestEpsilon(3) = thirdStageEps; bestZ = Z; bestLambda = lambda; bestMp = mp; bestMs = ms; end catch end end end end end fprintf('*********** earth to LEO with 3 stages **********\n'); if(minTotalMass>0) fprintf('deltaV=%f\n',deltaV); fprintf('min total mass=%f kg\n',minTotalMass); fprintf('m0 first stage= %f kg\n',mL+bestMp(1)+bestMp(2)+bestMp(3)+... bestMs(1)+bestMs(2)+bestMs(3)); fprintf('mf first stage= %f kg\n',mL+bestMp(3)+bestMp(2)+bestMs(1)+bestMs(2)+bestMs(3)); fprintf('m0 second stage= %f kg\n',mL+bestMp(2)+bestMp(3)+bestMs(2)+bestMs(3)); fprintf('mf second stage= %f kg\n',mL+bestMs(2)+bestMs(3)+bestMp(3)); fprintf('m0 third stage= %f kg\n',mL+bestMp(3)+bestMs(3)); fprintf('mf third stage= %f kg\n',mL+bestMs(3)); fprintf('best Ve first Stage=%f km/sec \n',bestVe(1)); fprintf('best Ve second Stage=%f km/sec \n',bestVe(2)); fprintf('best Ve third Stage=%f km/sec \n',bestVe(3)); fprintf('best Isp first stage=%f sec\n',bestVe(1)/g * 1000); fprintf('best Isp second stage=%f sec\n',bestVe(2)/g * 1000); fprintf('best Isp third stage=%f sec\n',bestVe(3)/g * 1000); fprintf('best Epsilon first stage=%f \n',bestEpsilon(1)); fprintf('best Epsilon second stage=%f \n',bestEpsilon(2)); fprintf('best Epsilon third stage=%f \n',bestEpsilon(3)); fprintf('best Z first stage=%f \n',bestZ(1)); fprintf('best Z second stage=%f \n',bestZ(2)); fprintf('best Z third stage=%f \n',bestZ(3)); fprintf('best lambda first stage=%f \n',bestLambda(1)); fprintf('best lambda second stage=%f \n',bestLambda(2)); fprintf('best lambda third stage=%f \n',bestLambda(3)); fprintf('best mp first stage =%f \n',bestMp(1)); fprintf('best mp second stage =%f \n',bestMp(2)); fprintf('best mp third stage =%f \n',bestMp(3)); fprintf('best ms first stage =%f \n',bestMs(1)); fprintf('best ms second stage =%f \n',bestMs(2)); fprintf('best ms third stage =%f \n',bestMs(3)); else fprintf('Failed to find any one stage that will meet deltaV with given Isp\n'); fprintf('Please increase number of stages of increase Isp or reduce payload\n'); end