Simple Questions, Please Answer 2

hi i'm new and learning about genetic algorithm sample codes
this is part of the code:
for p=1:popsize
for n=1:nd
r=rand;
if r<pm
new(p,n)=a*old(p,n)*rand;
else
new(p,n)=old(p,n);
end
end
end
i can't find any old(p,n) function, but it still can run. is old a function provided by the matlab? if so, is there a link to learn about it?
thank you

Respuestas (1)

per isakson
per isakson el 24 de En. de 2019
Editada: per isakson el 24 de En. de 2019
old is not the name of a Matlab function. Maybe you have a variable named old
What does
which old
return?

4 comentarios

Antoni Ho
Antoni Ho el 24 de En. de 2019
Editada: per isakson el 24 de En. de 2019
function new=ymutr1(old,popsize,nd,pm,a)
for p=1:popsize
for n=1:nd
r=rand;
if r<pm
new(p,n)=a*old(p,n)*rand;
else
new(p,n)=old(p,n);
end
end
end
end
this is all he wrote, i believe there's no defining old in another file. however, old is also used in another function file, but i'm dead sure, there's no defining code on it
per isakson
per isakson el 24 de En. de 2019
Editada: per isakson el 24 de En. de 2019
"this is all he wrote" Not quite. In addition you called the function. old is the first input argument of the function.
Antoni Ho
Antoni Ho el 24 de En. de 2019
"old is the first input argument of the function."
exactly, so the defining of the old should be in this same file right? but there is none.
per isakson
per isakson el 24 de En. de 2019
Editada: per isakson el 24 de En. de 2019
"[...] old should be in this same file right?" No, typically not. Only if ymutr1 is a local or nested function.
The code you showed in a previous comment is that the only content of a file named, ymutr1.m? If so, how did you make this function run? Somewhere there is a call like
out = ymutr1( first_input, second_input, x3, x4, x5 )
in another function or in a script or in the command window. The names of the arguments doesn't matter. See function, Declare function name, inputs, and outputs. old will take the value of first_input.
How did you call ymutr1?

La pregunta está cerrada.

Preguntada:

el 24 de En. de 2019

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by