how I use function F = myfun1(x,xdata) F= @(x,xdata)x(1).*exp(x(2).*xdata);
조회 수: 12 (최근 30일)
이전 댓글 표시
function F = myfun1(x,xdata)
F= @(x,xdata)x(1).*exp(x(2).*xdata);
% Assume you determined xdata and ydata experimentally
xdata = [0.9 1.5 13.8 19.8 24.1 28.2 35.2 60.3 74.6 81.3];
ydata = [455.2 428.6 124.1 67.3 43.2 28.1 13.1 -0.4 -1.3 -1.5];
x0 = [100, -1]; % Starting guess
x = lsqcurvefit(@myfun1,x0,xdata,ydata);
Error: Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.
댓글 수: 0
답변 (1개)
Rajanya
2025년 7월 1일
The following line makes 'F' a function handle to an anonymous function-
F= @(x,xdata)x(1).*exp(x(2).*xdata);
Changing the function definition of 'myfun1' to the following returns a vector of predicted values-
function F = myfun1(x,xdata)
F = x(1).*exp(x(2).*xdata);
end
Then, the error is resolved.
xdata = [0.9 1.5 13.8 19.8 24.1 28.2 35.2 60.3 74.6 81.3];
ydata = [455.2 428.6 124.1 67.3 43.2 28.1 13.1 -0.4 -1.3 -1.5];
x0 = [100, -1]; % Starting guess
x = lsqcurvefit(@myfun1,x0,xdata,ydata);
x
To learn more about anonymous functions and how they are used, you can refer to its documentation by executing the following command from MATLAB Command Window-
doc Anonymous Functions
Thanks!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Computations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!