필터 지우기
필터 지우기

Given Dataset, find Optimal Parameters of a Definite Integral Function

조회 수: 4 (최근 30일)
EC
EC 2022년 3월 28일
답변: Vatsal 2023년 12월 26일
Suppose I know the relationship between y and x to be:
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.

답변 (1개)

Vatsal
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!

카테고리

Help CenterFile Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by