- Use the {} Code button to format your code.
- Show us your call to GA, such as
Error when using variable to be optimized in a cycle for
1 view (last 30 days)
Show older comments
Hi, I am trying to optimize the following function, which depends on a variable n (I want for it to be minimized):
function [y] = BOH(n) somma=1; x=1:1:n; for i=1:1:length(x) somma=somma+1/(factorial(x(i))*4^(x(i))) end y=20/((4^n)*factorial(n))*(16*n^2)/((4*n-1)^2)*1/(somma-(1/(factorial(n)*4^n))+(4*n)/(4^n*factorial(n)*(4*n-1)))
I got the following error:
"Optimization running. Error running optimization. N must be an array of real non-negative integers"
May be it depends on the fact that I want to cycle from 1 to n, where n is not defined yet. As n is the variable I want to optimize, could you please help me to understand how to re-write the function properly? Thanks and regards.
1 Comment
Alan Weiss
on 15 Dec 2014
Please do two things to help us understand you:
[x fval] = ga(@BOH,1,[],[],[],[],[],[],[],1)
Alan Weiss
MATLAB mathematical toolbox documentation
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!