Finding equation of a line in R^3

4 visualizaciones (últimos 30 días)
Ege Gurtan
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)

Respuesta aceptada

Star Strider
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
Ege Gurtan
Ege Gurtan el 1 de Sept. de 2017
Wow I am really surprised :D. Can you please explain me what is going on here mathematically? and in terms of matlab. Thank you very much
Star Strider
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!

Iniciar sesión para comentar.

Más respuestas (1)

Rik
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
Ege Gurtan
Ege Gurtan el 1 de Sept. de 2017
Editada: Ege Gurtan el 1 de Sept. de 2017
Is it not possible to write a script that solves this? I can calculate it by hand but I have a lot of data that's why I need a script to calculate rapidly

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by