2nd Order Polynomial Coefficient Solving

I have been having very good success with guidance from the community with using Curve Fitter. I now would like to produce coefficients with an added variable.
I have the Data for R,S,P,T.
T = a + b*P + c*S + d*S^2 + e*(S*P) + f*(S^2*P)
Trying to find coefficients a,b,c,d,e,f.
The coefficients would a median seperated by 'R' breakpoints [550 725 950] , so realistically I would have a 6x3 matrix of coefficients.
At the moment linear regression will work, but the affect of P on T is linear, and the affect of R and S on T is non-linear in reality.
I have a 63000 x 4 matrix for data.
R S P T
716 28.5000000000000 291.727272727300 184.407961051320
721 28.5000000000000 291.625000000000 187.140145995908
721 28.5000000000000 291.625000000000 187.220504376631
722.5 28.5000000000000 291.625000000000 187.140145995908
722.5 28.5000000000000 291.625000000000 187.140145995908
I tried this along with a couple other methods to no avail.
Ignore the column indices, that was another iteration from the above data.
TRQ1 = @(c,VAR) c(1).*VAR(:3) + c(2) + c(3).*VAR(:,2) + c(4).*VAR(:,4) + c(5).*VAR(:,5) + c(6).*VAR(:,6);
F_TRQ= linsolve(VAR(:,[1 3] ) , TRQ, TRQ1)

 Respuesta aceptada

Torsten
Torsten el 29 de Ag. de 2024
Editada: Torsten el 29 de Ag. de 2024
I don't see R in your regression equation
T = a + b*P + c*S + d*S^2 + e*(S*P) + f*(s^2*P)
And I assume that "s" means "S".
M = [ones(63000,1),P,S,S.^2,S.*P,S.^2.*P];
y = T;
x = M\y;
a = x(1)
b = x(2)
c = x(3)
d = x(4)
e = x(5)
f = x(6)

11 comentarios

Eric
Eric el 29 de Ag. de 2024
Yes, I edited the s to S. The constant "a" would change if between each set of coefficients based of R
Torsten
Torsten el 29 de Ag. de 2024
Thus problem solved ?
Eric
Eric el 29 de Ag. de 2024
Editada: Eric el 29 de Ag. de 2024
Thank You!. I am going to dig deeper now on how to add constraints to the coefficients and how to incorporate the constant related to R
Torsten
Torsten el 29 de Ag. de 2024
Editada: Torsten el 29 de Ag. de 2024
If you have to put constraints on the coefficients, use "lsqlin" to solve the overdetermined linear system M*x = y.
E.g.
M = [ones(63000,1),P,S,S.^2,S.*P,S.^2.*P];
y = T;
lb = [...]; % lower bounds on the coefficients
ub = [...]; % upper bounds on the coefficients
x = lsqlin(M,y,[],[],[],[],lb,ub);
a = x(1)
b = x(2)
c = x(3)
d = x(4)
e = x(5)
f = x(6)
Eric
Eric el 29 de Ag. de 2024
So far I havent needed constraints yet, which I was surprised about. Still hung up on using R for an index/value. I tried replacing 'ones' with R and it seemed to be in the right direction but R I turned my constant into an coefficient which I know is incorrect.
Eric
Eric el 30 de Ag. de 2024
After more research, I cant seem to make the data do what I want.
I am trying to have only the constant x(1) linked to data from R. So it would be the "offset" based off R.
Thank you again!
From what I understand, you want something similar to this ?
T1 = T(R<=550);
P1 = P(R<=550);
S1 = S(R<=550);
n1 = numel(T1);
T2 = T(R>550 & R<=725);
P2 = P(R>550 & R<=725);
S2 = S(R>550 & R<=725);
n2 = numel(T2);
T3 = T(R>725);
P3 = P(R>725);
S3 = S(R>725);
n3 = numel(T3);
M = [[ones(n1,1);zeros(n2,1);zeros(n3,1)],[zeros(n1,1);ones(n2,1);zeros(n3,1)],...
[zeros(n1,1);zeros(n2,1);ones(n3,1)],[P1;P2;P3],[S1;S2,S3],[S1.^2;S2.^2;S3.^2],...
[S1.*P1;S2.*P2;S3.*P3],[S1.^2.*P1;S2.^2*P2;S3.^2*P3]];
y = [T1;T2;T3];
x = M\y;
a1 = x(1)
a2 = x(2)
a3 = x(3)
b = x(4)
c = x(5)
d = x(6)
e = x(7)
f = x(8)
Eric
Eric el 31 de Ag. de 2024
I think so, but need to keep the total amount of coefficients including the constant to 6.
M = [[ones(n1,1);zeros(n2,1);zeros(n3,1)],[zeros(n1,1);ones(n2,1);zeros(n3,1)],...
[zeros(n1,1);zeros(n2,1);ones(n3,1)],[P1;P2;P3],[S1;S2,S3],[S1.^2;S2.^2;S3.^2],...
[S1.*P1;S2.*P2;S3.*P3],[S1.^2.*P1;S2.^2*P2;S3.^2*P3]];
I think that sould be [S1;S2;S3] instead of [S1;S2,S3]
Torsten
Torsten el 31 de Ag. de 2024
Thank you.
You get 6 coefficients. The first coefficient depends on R. The regression equation solved above is
T = x(1) + x(4)*P + x(5)*S + x(6)*S^2 + x(7)*(S*P) + x(8)*(S^2*P) if R <= 550
T = x(2) + x(4)*P + x(5)*S + x(6)*S^2 + x(7)*(S*P) + x(8)*(S^2*P) if R > 550 & R <=725
T = x(3) + x(4)*P + x(5)*S + x(6)*S^2 + x(7)*(S*P) + x(8)*(S^2*P) if R > 725
Eric
Eric el 1 de Sept. de 2024
Thank you so much. I will now keep my head down and keep working on learning.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 28 de Ag. de 2024

Comentada:

el 1 de Sept. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by