Finding equation of a line in R^3
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ege Gurtan
el 1 de Sept. de 2017
Comentada: Star Strider
el 1 de Sept. de 2017
I have a voltage function. It depends on pressure and resistance. (V as a function of P and R. V(P,R)
I have two points in 3-D. (x,y,z) where x is pressure, y is resistance and z is voltage. Please help me to find z in terms of x and y. My points are
(1,7,9) and (2,5,11)
0 comentarios
Respuesta aceptada
Star Strider
el 1 de Sept. de 2017
Without knowing what your function actually is, fitting it to your data is not possible.
A linear fit is straightforward:
D = [ 1 7 9; 2 5 11];
B = [D(:,1) D(:,2)]\D(:,3);
fprintf('\n\tV = %.2f·P + %.2f·R\n', B)
V = 3.56·P + 0.78·R
2 comentarios
Star Strider
el 1 de Sept. de 2017
As always, my pleasure.
Mathematically, it is simple linear approximation. In terms of MATLAB functions, it is the least-squares solution to a system of linear equations, where the first column of ‘D’ is assumed to be Pressure, the second column is assumed to be Resistance, and the third column, Voltage. The (:,k) where ‘k’ is an integer refers to all rows of column ‘k’, necessary here to get the matrix correct. I could have use ‘D(:,1:2)’ instead:
B = D(:,1:2)\D(:,3);
however the syntax I used originally is a bit more straightforward to understand.
See the documentation on ‘matrix left division’ (the mldivide,\ (link) function) for all the interesting details. See also the documentation on Matrix Indexing (link) and colon (link) to further explain my code. I created the printed output with the fprintf (link) function. It is worth learning about as well.
MATLAB is powerful. There are aspects of it that still surprise me!
Más respuestas (1)
Rik
el 1 de Sept. de 2017
You can solve this with pen and paper, or use fit. You can open the documentation to help you along by running doc fit. fit will probably throw a warning about overfitting.
If this isn't enough to help you solve this, just post a comment and I'll try to clarify.
1 comentario
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!