Given Dataset, find Optimal Parameters of a Definite Integral Function
조회 수: 4 (최근 30일)
이전 댓글 표시
Suppose I know the relationship between y and x to be:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/943399/image.jpeg)
which does not have a closed form solution.
x0 and m are known and positive real numbers. a, b and c are parameters which I want to obtain for a given dataset, which contains N data points: (x1,y1), (x2,y2),...(xi,yi)...(xN,yN).
How can I implement a code in MATLAB to find the optimal values of a, b and c to minimize the sum of square errors?
I've tried the following code, where xIn and yIn are vectors consisting the data points and D = [a b c]'. MATLAB returns an error that for the integral function, the upper bound has to be a scalar.
fun = @(D)integral(@(x)(D(1)*x.^2 + D(2)*x + D(3)).^-m,x0,xIn) - yIn;
D0 = [1 1 1];
D = lsqnonlin(fun,a0);
Any help will be greatly appreciated.
댓글 수: 0
답변 (1개)
Vatsal
2023년 12월 26일
Hi,
I understand that you want to find Optimal Parameters of a Definite Integral Function. The issue you are encountering is because MATLAB’s "integral" function expects the upper and lower bounds of the "integral" to be scalars, not vectors. However, in the provided code “xIn” is passed as upper bound, which is a vector. To resolve this, the code should be modified to process each data point separately, accumulating the squared errors from all points. This involves iterating through each data point, evaluating the integral with the specific “x” value as the upper bound, and then calculating the squared error.
Below is the modified code to accomplish this:
fun = @(D) sum(arrayfun(@(x, y) (integral(@(t)(D(1)*t.^2 + D(2)*t + D(3)).^-m, x0, x) - y)^2, xIn, yIn));
D0 = [1 1 1];
D = lsqnonlin(fun, D0);
I hope this helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!