Finding equation of a line in R^3
4 次查看(过去 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)
0 个评论
采纳的回答
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 个评论
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
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!