How to fit data in an array to a multidimensional function?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Philipp Müller
am 16 Dez. 2022
Bearbeitet: Torsten
am 20 Dez. 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
0 Kommentare
Akzeptierte Antwort
Torsten
am 16 Dez. 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 Kommentare
Torsten
am 20 Dez. 2022
Bearbeitet: Torsten
am 20 Dez. 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)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!