how to optimize the integral function?

function F =t(x)
syms e
k=1:511;
F=int((abs(sinc(x*(k+e)))).^2/(abs(sinc(x*e))).^2,e,0,1);
[x,resnorm]=lsqnonlin(@t,0,0,1);
i want to optimize the function 'F' and parameter is 'x' when i run the program error occurred:
Undefined function or method 'isfinite' for input arguments of type 'sym'.
Error in ==> snls at 45 if any(~isfinite(fval))
Error in ==> lsqncommon at 149 [xC,FVAL,LAMBDA,JACOB,EXITFLAG,OUTPUT,msgData]=...
Error in ==> lsqnonlin at 238 [xCurrent,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
Error in ==> l at 2 [x,resnorm]=lsqnonlin(@t,0,0,1)

답변 (1개)

Alan Weiss
Alan Weiss 2013년 4월 18일

0 개 추천

You have several problems in your code.
  • Optimization Toolbox uses doubles, not symbolic variables.
  • Your function seems to be calling itself (lsqnonlin(@t... occurs inside the definition of t as far as I can see)
To convert from symbolic to numeric, use subs, or the much faster matlabFunction. See this example or this example.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

카테고리

도움말 센터File Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

태그

질문:

2013년 4월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by