Function works with one input but not the other

Im using the optimisation tool and have set everything up following the tutorial on the mathwork website, the tool works when the input is Y but not when the input is T_to, which is what id like it to be. T_to input only works when the number of variables is one, which doesnt give me a useful result.
I should disclose im still very new to matlab so its possible that the problem is very simple.
function F = mymulti1(T_to)
y = 20640000;
%T_to = 3050; %degC
A_choke = 0.0531; %m^2
A_Rat = 78;
A_Exit = A_choke * A_Rat; %m^2
T_Exit = 343.2;
M_Exit = 1.65; %Ratio
Gamma = 1.26; %Const
Gas_const = 287.5; %Const
MFR = ((A_choke * y) ./ (sqrt(T_to))) * (sqrt(Gamma / Gas_const)) * ( ((Gamma + 1) / 2)^-((Gamma + 1) / 2*(Gamma - 1)));
Pressure_Exit = (1 + ((Gamma - 1) / 2) * ((M_Exit) ^ 2))^ - (Gamma /(Gamma - 1)) * y;
Velocity_Exit = M_Exit * sqrt(Gamma * Gas_const * T_Exit);
Thrust = (MFR .* Velocity_Exit) + (A_Exit * Pressure_Exit);
F(2) = Thrust ./ MFR ;
F(1) = (y .* A_choke) ./ MFR;
end

Answers (1)

F(2,:) = Thrust ./ MFR ;
F(1,:) = (y .* A_choke) ./ MFR;
Check the size of output matrix

10 Comments

Definitely some progress, the new error message is below.
Unable to perform assignment because the size of the left side is 1-by-20 and the size of the right side is 2-by-10.
Fvals(i,:) = feval(objFcn,(pop(i,:)));
[Score,C,Ceq,isFeas] = objAndConVectorizer(state.Population(initScoreProvided+1:end,:), ...
state = gamultiobjMakeState(GenomeLength,FitnessFcn,ConstrFcn,output.problemtype,options);
Error in gamultiobj (line 334)
[x,fval,exitFlag,output,population,scores] = gamultiobjsolve(FitnessFcn,nvars, ...
Caused by:
Failure in user-supplied fitness function evaluation. Cannot continue.
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
F(2) = Thrust ./ MFR ;
fcn_handle = @(x) fcn(x,FcnArgs{:});
Score = FitnessFcn(state.Population(1,:));
state = gamultiobjMakeState(GenomeLength,FitnessFcn,ConstrFcn,output.problemtype,options);
Error in gamultiobj (line 334)
[x,fval,exitFlag,output,population,scores] = gamultiobjsolve(FitnessFcn,nvars, ...
Caused by:
Failure in initial fitness function evaluation. GAMULTIOBJ cannot continue.
so yes the sizes are different, how would i change them?
F(2,:,:) = Thrust ./ MFR ;
F(1,:,:) = (y .* A_choke) ./ MFR;
Unable to perform assignment because the size of the left side is 1-by-20 and the size of the right side is 2-by -1 by -10
F{2} = Thrust ./ MFR ;
F{1} = (y .* A_choke) ./ MFR;
Try using a cell array
There are significantly less error messages now, but im still getting this one.
Conversion to double from cell is not possible.
state.Score(1:initScoreProvided,:) = options.InitialScores(1:initScoreProvided,:);
state = gamultiobjMakeState(GenomeLength,FitnessFcn,ConstrFcn,output.problemtype,options);
Error in gamultiobj (line 334)
[x,fval,exitFlag,output,population,scores] = gamultiobjsolve(FitnessFcn,nvars, ...
F{2} = Thrust ./ MFR ;
F{1} = (y .* A_choke) ./ MFR;
F = cell2mat(F);
Convert to double array. It looks the standard function , gamutli doesn't take cell arrays.
this has solved the issue and provided me with a 3d plot.
ideally it would be 2d but ill take what i can get at this point.
Do yo know how id turn this into a good looking pareto graph with a range of values??
Try A histogram plot in output display
Hi VBBV,
you've helped already a massive amount but if i could just trouble you a little more.
attached is the plot ive got and the kind of plot im trying to get. what would you recommend i do?
Thanks
Samir

Sign in to comment.

Categories

Products

Release

R2021b

Asked:

on 14 Apr 2022

Commented:

on 14 Apr 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!