How to fit data in an array to a multidimensional function?
5 次查看(过去 30 天)
显示 更早的评论
Hey there,
I have an 10x20x6 double Array. Those data inside should now be fit in an optimal way (e.g. nonlinear LS) to a function f(x,y,z).
The arrays colums corresponds to the x axis, the rows to the y axis and the depth to the z axis. The array entries should correspond to the functions value, respectively.
The function f has the form f = a1*x^2 + a2*x + b1*y^2 + b2*y + c1*z^2 + c2*z + d
The aim is, to find a1, a2, b1, b2, c1, c2 and d
I'd be very gratefull, if someone could explain to me, how to handle such a multidimensional fitting
0 个评论
采纳的回答
Torsten
2022-12-16
Generate four 1d column vector X,Y,Z and F of your data where F(i) is the value of your function corresponding to F(X(i),Y(i),Z(i)).
Then you can easily obtain the fit coefficients as
A = [X.^2,X,Y.^2,Y,Z.^2,Z,ones(size(X))];
b = F;
sol = A\b;
a1 = sol(1)
a2 = sol(2)
b1 = sol(3)
b2 = sol(4)
c1 = sol(5)
c2 = sol(6)
d = sol(7)
2 个评论
Torsten
2022-12-20
编辑:Torsten
2022-12-20
If your coordinate vectors are x(1:20),y(1:10) and z(1:6) and your 10x20x6 matrix is M,
count = 0;
X = zeros(10*20*6,1);
Y = zeros(10*20*6,1);
Z = zeros(10*20*6,1);
F = zeros(10*20*6,1);
for i = 1:10
for j = 1:20
for k = 1:6
count = count + 1;
X(count) = x(j);
Y(count) = y(i);
Z(count) = z(k);
F(count) = M(i,j,k);
end
end
end
A = [X.^2,X,Y.^2,Y,Z.^2,Z,ones(size(X))];
b = F;
sol = A\b;
a1 = sol(1)
a2 = sol(2)
b1 = sol(3)
b2 = sol(4)
c1 = sol(5)
c2 = sol(6)
d = sol(7)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interpolation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!