Azzera filtri
Azzera filtri

Finding equation of a line in R^3

3 visualizzazioni (ultimi 30 giorni)
Ege Gurtan
Ege Gurtan il 1 Set 2017
Commentato: Star Strider il 1 Set 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)

Risposta accettata

Star Strider
Star Strider il 1 Set 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 Commenti
Ege Gurtan
Ege Gurtan il 1 Set 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 il 1 Set 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!

Accedi per commentare.

Più risposte (1)

Rik
Rik il 1 Set 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 Commento
Ege Gurtan
Ege Gurtan il 1 Set 2017
Modificato: Ege Gurtan il 1 Set 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

Accedi per commentare.

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by