Good day everyone,
I have this pack of data that are functions of three variables (say, x1, x2 and x3). How do I choose a linear approximating function that minimizes the maximum error between the linear function and the data? I'm getting some approximating functions with an other software that cannot provide this specific detail to choose between them, though, so I'm quite stuck.
On the other hand I've been suggested to use fminimax in MatLab, but it doesn't seem to be usable in this case (to me, and I'm not a "so experienced user" so I may be wrong).
Thank you so much in advance!
Stefano

 Akzeptierte Antwort

Torsten
Torsten am 7 Jun. 2023
Bearbeitet: Torsten am 7 Jun. 2023

0 Stimmen

By a "linear approximating function" you mean a function l with
l(x1,x2,x3) = a + b*x1 + c*x2 + d*x3
where a, b, c and d are constants that have to be determined as to minimize the maximum of
abs(a + b*x1 + c*x2 + d*x3 - y)
?
Use "linprog" to solve the optimization problem
min: t
s.c.
a + b*x1 + c*x2 + d*x3 - y <= t
a + b*x1 + c*x2 + d*x3 - y >= -t

1 Kommentar

Stefano Gilardoni
Stefano Gilardoni am 7 Jun. 2023
Thank you for your answer, I'll try the solution you're suggesting! Does it work also when y is a vector? And does this function choose a, b, c and d to minimize the abs(delta)?
I do not know linprog, so I have to ask that... Thank you again.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Torsten
Torsten am 7 Jun. 2023
Verschoben: Torsten am 7 Jun. 2023

0 Stimmen

Example:
rng('default')
n = 100;
x1 = rand(n,1);
x2 = rand(n,1);
x3 = rand(n,1);
y = rand(n,1);
f = [1; 0 ;0; 0; 0];
A = [-ones(n,1),ones(n,1),x1,x2,x3;-ones(n,1),-ones(n,1),-x1,-x2,-x3];
b = [y;-y];
[sol,fval] = linprog(f,A,b)
Optimal solution found.
sol = 5×1
0.4865 0.4639 0.0450 0.0258 0.0348
fval = 0.4865
t = sol(1)
t = 0.4865
a = sol(2)
a = 0.4639
b = sol(3)
b = 0.0450
c = sol(4)
c = 0.0258
d = sol(5)
d = 0.0348

3 Kommentare

Stefano Gilardoni
Stefano Gilardoni am 8 Jun. 2023
Perfect, thank you again. I'll test it out this morning!
Stefano Gilardoni
Stefano Gilardoni am 8 Jun. 2023
I'm still trying to use linprog on the problem I have. Once that I will have understood linprog and solved the problem with this function, then I will accept your answer! Thank you again.
Instead of
x1 = rand(n,1);
x2 = rand(n,1);
x3 = rand(n,1);
y = rand(n,1);
you just have to supply your data as column vectors.

Melden Sie sich an, um zu kommentieren.

Produkte

Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by