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

 채택된 답변

Torsten
Torsten 2023년 6월 7일
편집: Torsten 2023년 6월 7일

0 개 추천

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

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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Torsten
Torsten 2023년 6월 7일
이동: Torsten 2023년 6월 7일

0 개 추천

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

Perfect, thank you again. I'll test it out this morning!
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.

댓글을 달려면 로그인하십시오.

카테고리

제품

릴리스

R2023a

질문:

2023년 6월 7일

댓글:

2023년 6월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by