Fit a linear equation to obtain coefficients (constants)

3 visualizaciones (últimos 30 días)
Learning
Learning el 10 de En. de 2025
Comentada: Altaïr el 3 de Feb. de 2025
Hi, I have a linear equation P = a + bM + c(Y-1) + d(M(Y-1)) where a, b, c and d are coefficients (constants). P, Y and M are known properties. Specifically, there are multiple P values, each with their corresponding Y and M values. How do I use matlab or excel to fit the data to the equation above to obatin the a, b, c & d coefficients? Please see image below. So each P value has 2 Y values and 2 M values. Any ideas?

Respuestas (2)

Matt J
Matt J el 10 de En. de 2025
Editada: Matt J el 10 de En. de 2025
I have a linear equation P = a + bM + c(Y-1) + d(M(Y-1)) where a, b, c and d are coefficients (constants). P, Y and M are known properties.
If your model is P = a + bM + c(Y-1) + d(M(Y-1)), then it can be written in matrix/vector form P=A*x where x=[a,b,c,d] and
P=P(:); M=M(:); Y=Y(:); e=ones(size(M));
A=[e,M,(Y-1),M*(Y-1)]
and you could solve it this way,
x=A\P
However,
So each P value has 2 Y values and 2 M values.
that won't work. You would need at least 4 values of M,Y,P to obtain a unique solution for 4 variables. And that is true of any solution approach, not just the one I outline above.
  3 comentarios
Learning
Learning el 10 de En. de 2025

Hi, thank you and you are right, that’s exactly what the table is meant to demonstrate. Curious any code I can use to start? Challenging to see how to feed in the data to obtain those coefficient. Much appreciated!

Matt J
Matt J el 11 de En. de 2025
Curious any code I can use to start?
It's been shown. Write your equations in matrix form P=A*x and solve with x=A\P.

Iniciar sesión para comentar.


Altaïr
Altaïr el 10 de En. de 2025
Editada: Altaïr el 10 de En. de 2025
Hello,
A linear model essentially fits a hyperplane, where each combination of independent variables is mapped to a single value of the dependent variable. Since there are two combinations of Y and M values for each value of P, a higher degree equation might be necessary. The Curve Fitting Toolbox offers several options for this. Here's a helpful example to get started:
This example demonstrates how to perform curve fitting using a polynomial curve. The Curve Fitter should help in figuring out the best suitable model for the data interactively.
  2 comentarios
John D'Errico
John D'Errico el 10 de En. de 2025
This IS a linear model, purely linear in the unknown parameters. Many people misunderstand the difference between a model that is linear in the parameters, and one that is intrinsicly nonlinear. There is no need to use a nonlinear curve fitting tool to fit such a model. Even backslash will do the trick.
By way of comparison, the model
z = a + b*x + c*y
is a classicaly linear model, in terms of how it behaves with respect to both x and y, but also in the parameters. If you plot the surface, this first model form will be a truly planar surface, with no curvature at all anywhere. However, change it slightly, like this:
z = a + b*x + c*exp(y)
is still a linear model in terms of the parameters a, b, and c. One would still employ the same linear modeling tools to estimate a, b and c. Similarly, the model
z = a + b*x + c*y + d*x*y
is nonlinear in terms of the shape, and how it behaves under changes in x and y, but it is purely linear in the parameters. Again, a tool as simple as backslash is capable of performing the fit, as well as many other tools that have no need to operate with truly nonlinear models in the parameters. In fact, this third example is one that is essentially the same as that in the question from @Learning.
If we change things just a bit more though,
z = a + b*x + c*exp(d*y)
now the model is nonlinear in both the unknown parameters (a,b,c,d) and in the shape of the resulting surface.
Altaïr
Altaïr el 3 de Feb. de 2025
Thats good to know!

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by