I'm trying to run this program through Optimtool but getting the errors - "Undefined function 'symsum' for input arguments of type double". Can somebody help me with this code?

Attached Picture is the actual question. I want to perform a Simulated Annealing algorithm on this question to find the number of iterations occurring before reaching the final value. Here is the code that I wrote -
function y = SAcode(N)
syms i
y = symsum((N(1)-3).^2+(N(2).^(i)-3).^2 +(N(3).^(i)-3).^2,i,1,N(1));
end
ObjectiveFunction = @SAcode;
n = [2 2.4 3.6];
lb = [1 1 1];
ub = [5 5 5];
[N,fval,exitFlag,output] = simulannealbnd(ObjectiveFunction,n,lb,ub);
fprintf('The number of iterations was : %d\n', output.iterations);
fprintf('The number of function evaluations was : %d\n', output.funccount);
fprintf('The best function value found was : %g\n', fval);

 採用された回答

>> N =[20:23]
syms k
y = symsum((N(1)-3).^2+(N(2).^(K)-3).^2 +(N(3).^(K)-3).^2,K,1,N(1));
N =
20 21 22 23
>> y
y =
576242485144297694059340321398556670349680706722787840
>>

10 件のコメント

madhan ravi
madhan ravi 2018 年 10 月 29 日
The above shows an example but I didn't get any trouble getting the result
But when I'm trying to run the same function for Simulated Annealing, it is giving me the error. The attached picture is what I'm getting.
I think symbolic operations are not allowed in optimisation maybe try:
N =[20:23]
K=1:N(1)
y = cumsum((N(1)-3).^2+(N(2).^(K)-3).^2 +(N(3).^(K)-3).^2);
y(end)
Yeah. It finally ran. Thank you so much.
The program did ran, but in the output I found that only two values of N are displayed. What could be the explanation for that?
madhan ravi
madhan ravi 2018 年 10 月 29 日
Two values of N are displayed
I don’t understand , mind explaining?
Aditya Banerjee
Aditya Banerjee 2018 年 10 月 29 日
編集済み: Aditya Banerjee 2018 年 10 月 29 日
This is what I got in output.
Optimization terminated: change in best function value less than options.FunctionTolerance.
The number of iterations was : 1000
The number of function evaluations was : 1009
The best function value found was : 5
>> [N,fval,exitFlag,output] = simulannealbnd(ObjectiveFunction,n,lb,ub)
Optimization terminated: change in best function value less than options.FunctionTolerance.
N =
2.4000 3.6000
fval =
5
exitFlag =
1
madhan ravi
madhan ravi 2018 年 10 月 29 日
I don’t have any experience with optimisation so my knowledge is limited in this field sorry
No problem. Thank you so much for the rectification.
madhan ravi
madhan ravi 2018 年 10 月 29 日
Anytime :) glad that I could help

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by