Given Dataset, find Optimal Parameters of a Definite Integral Function
1 次查看(过去 30 天)
显示 更早的评论
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.
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!