Finding equation of a line in R^3

3 次查看(过去 30 天)
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)

采纳的回答

Star Strider
Star Strider 2017-9-1
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 个评论
Ege Gurtan
Ege Gurtan 2017-9-1
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 2017-9-1
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!

请先登录,再进行评论。

更多回答(1 个)

Rik
Rik 2017-9-1
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 个评论
Ege Gurtan
Ege Gurtan 2017-9-1
编辑:Ege Gurtan 2017-9-1
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by