I need help obtaining the values c1,c2.c3 from a least squares fit of the data.
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I need help obtaining the values c1,c2.c3 from a least squares fit of the data.
2 comentarios
James Tursa
el 29 de Jul. de 2020
What have you done so far? What specific problems are you having with your code?
Respuestas (1)
James Tursa
el 29 de Jul. de 2020
Editada: James Tursa
el 29 de Jul. de 2020
It appears to me that your equation is linear in c1, c2, c3. Just make a matrix equation out of this and then apply your least squares technique to the matrix. That is, you know everything in that equation except the c1, c2, c3. So just calculate all the values for each set of data and that will give you a matrix equation of the form:
b = A*c
where
each elemet of b is calculated from your data (the ln(Psat/Pc) values)
each row of A is calculated from your data corresponding to the element of b (the x, x^2, ln(Tsat/Tc) values)
c is simply the unknown column vector [c1;c2;c3]
Then use your least squares technique to solve for c.
4 comentarios
James Tursa
el 30 de Jul. de 2020
Lovie Reid Answer moved here:
I've removed the ones(size(x)) I was just using other examples to help, but would this be right for the least squares
a = polyfit(x,y,2);
James Tursa
el 30 de Jul. de 2020
Editada: James Tursa
el 30 de Jul. de 2020
polyfit(x,y,2) would be used if you had a set of x,y coordinates and you wanted to fit that with a 2nd degree polynomial. But you don't have that situation. You have a linear matrix equation with three variables that you are trying to fit. It is linear in the c1,c2,c3 terms. Using your variable names, you have this matrix equation (assuming you make y and x column vectors as I suggested):
y = z * c
You have three unknowns, the c = [c1;c2;c3], and 21 equations. An overdetermined linear system of equations where you know y and z. You are being asked to produce the least squares solution for c.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!