how can i fix subscript indices must be either real positive integers or logicals

2 visualizaciones (últimos 30 días)
I am new to matlab and i am tring to do multi objective optimization using gamultiobj , i have multi functions but when i try to run each function it says "Not enough input argument " plus when i try to run the main fun it says subscript indices must be either real positive integer or logicals" i have attached all of my functions!
  5 comentarios
metasebia dabi
metasebia dabi el 25 de Jun. de 2021
When I try to use
disp("Total Function Count:"+gaoutput1.funccount); It will make " red and tell me it is invalid characteristics
Walter Roberson
Walter Roberson el 25 de Jun. de 2021
Editada: Walter Roberson el 25 de Jun. de 2021
Then you are using R2015b or earlier, and should have mentioned that. You should switch to using fprintf()
fprintf('Total Function Count: %d\n', gaoutput1.funccount);
When someone says that they are new to MATLAB, we do not expect them to be using a version that is 5 years old.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 23 de Jun. de 2021
At a location approximately half way through the third line, you have
(x(60^3*(x(1) - x(2)))/6
You might possibly have intended something like (x(6)^3*(x(1)-x(2)))/6 . But watch out for just replacing the 0 with a ) -- you would have had to add an extra ) to get the ) to balance and there is no telling where you added it.
You appear to have used some kind of code generation to generate your code from a symbolic expression. I can tell that you did not use matlabFunction() just by itself -- but it is possible that you used matlabFunction() and then hand-editted pieces together.
I recommend that you go back to the code generation and tell it to optimize. Not so much that you want the optimization (though that would not hurt), but rather that you want the expressions to be split into multiple lines for readability.
And when you create the symbolic expressions that you are going to do code generation for, you should wrap every numeric constant with a sym() call, except that you can leave powers alone. Seeing numbers such as
(19515681011313314790985107421875*x(5))/73786976294838206464 in your code makes it clear that you just let it convert floating point constants to whatever was most convenient... that divisor is 2^66 exactly.
So for example,
syms t
c = 2.99792458e8
arfreq = 0.000000488;
obj = arfreq/c*t
you would instead do something like
syms t
Q = @(v) sym(v);
c = Q(299792458);
arfreq = Q(488)/sym(10)^9; %avoid floating point
obj = arfreq/c*t
In this case the pure numeric constants would lead to generating 2304514843640387*t/4722366482869645213696 but the more careful constants would lead to 61*t/37474057250000000 . Which is still a bit "funny money", magic constants with no obvious meaning to look at them, but they would be a lot more comprehendable, without the problems like 0.000000488 being converted to 2304514843640387/4722366482869645213696
  45 comentarios
Walter Roberson
Walter Roberson el 6 de Ag. de 2021
elseif S/6>tf> S/18,tf = tf;
MATLAB interprets that as meaning
elseif ((S/6>tf)> S/18)
tf = tf;
S/6>tf is calculated, returning 0 (false) or 1 (true). That 0 or 1 is then compared to S/18.
In this particular case it does not matter, since the branch effectively does nothing even if it works, but the code is misleading.
And you really should deal with the question of what to do if S/6 == tf exactly, or if tf < S/18 . If those cases are meaningful, then deal with them; if they are not meaningful then just have the if without any else.
You have a number of similar cases.
I suggest that you learn how to use min() and max(). Instead of writing something like
if C > 0.65
C = 0.65;
elseif C < 0.65
C = C;
end
just write
C = min(C, 0.65);
It is a bit counter-intuitive, but use min() when you want to set a value to be the maximum level something should have, and use max() when you want to set a value to be the minimum level something should have.
But other than those... unfortunately I do not know what I am looking at. Your design code calculates some things, but I have no idea how those things link to your previous code.
metasebia dabi
metasebia dabi el 6 de Ag. de 2021
I insert one of the final result of optimized solutions from my previous code , which are x1,x2,x3,x4,x5,x6,x7 and insert this results in the design code , the previous code is formulated using this design code so after inserting this results I run the code and calculate the result of safety factor Mn/Mr but in the optimization this result is fgal2 and the result is 11 but the out put of the original code using the optimized cross sections is 3,my question is why does it have this difference in results , is it b/c I use -f2 to maximize?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by