- #1
Hashmeer
- 16
- 0
Homework Statement
I'm trying to use fmincon to find the optimal mass ratios for the rocket equation. The only variables are m2/m1 and m3/m2 (R1 and R2 respectively).
The Attempt at a Solution
Code:
function [ velocity ] = rocketEqn( MR )
% Calculates the velocity that a rocket can attain given the mass ratios of
% the stages, where MR is a vector containing the mass ratios R1 and R2.
% MR = [R1, R2] and R1 = m2/m1 and R2 = m3/m2.
R1 = MR(1);
R2 = MR(2);
E = .1; %structural coefficient
Mp = 500; %payload mass
c = 3.3; %km/s^2, given exhaust velocity for the rocket
Mtot = 25000; % kg, given total mass of the rocket
M = Mtot - Mp; % gives the mass that can be dedicated to the rocket
%m1 + m2 + m3 = Mtot
%m2 = m1*R1;
%m3 = m2*R2;
m1 = M/(1 + R1 + R1*R2); %reworking the above equations to solve for the mass of stage 1
%following equations are used to find velocities that can be attained by
%each stage, rewritten to use only m1 in solving
v1 = c*log((m1 + m1*R1 + m1*R1*R2 + Mp)/(E*m1 + m1*R1 + m1*R1*R2 + Mp));
v2 = c*log((m1*R1 + m1*R1*R2 + Mp)/(E*m1*R1 + m1*R1*R2 + Mp));
v3 = c*log((m1*R1*R2 + Mp)/(E*m1*R1*R2 + Mp));
velocity = v1 + v2 + v3;
end
This is my code for finding the velocity that can be reached by a 3 stage rocket. This works when just solving for velocity, so I think I'm messing up when using the fmincon function in matlab.
Here is what I use to input into fmincon:
Code:
x0 = [.2,.2];
A = [];
b = [];
Aeq = [];
beq = [];
lb = [0,0];
ub = [1,1];
options = optimset('Algorithm', 'interior-point');
fmincon(@rocketEqn,x0,A,b,Aeq,beq,lb,ub,options)
There are no constraints on this except for R1 and R2 being between 0 and 1 (taken care of in the lb and ub). I'm getting an error that I have no clue how to fix: ? Error using ==> optimfcnchk at 297
NONLCON must be a function.
Error in ==> fmincon at 429
confcn =
optimfcnchk(NONLCON,'fmincon',length(varargin),funValCheck,flags.gradconst,false,true);
I'm pretty new to Matlab so any tips/advice would be very helpful.
Thanks.