How to fit data in an array to a multidimensional function?

12 vues (au cours des 30 derniers jours)
Philipp Müller
Philipp Müller le 16 Déc 2022
Modifié(e) : Torsten le 20 Déc 2022
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

Réponse acceptée

Torsten
Torsten le 16 Déc 2022
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 commentaires
Philipp Müller
Philipp Müller le 20 Déc 2022
Hey, thanks for your help,
but I wounder, how to put the array data in a 1d Vector. Its length would be 10*20*6 and so the part
sol = A\b;
returs a huge matrix, where
a1 = sol(1)
a2 = sol(2)
b1 = sol(3)
b2 = sol(4)
c1 = sol(5)
c2 = sol(6)
d = sol(7)
are all zero
Torsten
Torsten le 20 Déc 2022
Modifié(e) : Torsten le 20 Déc 2022
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)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Descriptive Statistics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by