How to find two variable function from scattered data?

Hi everyone!
I am getting started with MatLab and I would be very grateful if you can help me. How can I find approximating function of this 3D plot?
This is plot of my data which I need to approximate. In a book, I have found that this data should be approximated with two variable polynominal like this:
How can I solve this equations with my data in matlab?
Regards, Sergiusz.

1 件のコメント

Rik
Rik 2017 年 3 月 6 日
If you have the symbolic toolbox, you can try solve.

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2017 年 3 月 6 日

0 投票

function Avals = approximate_f5(nbar, Z, mbar)
nbar = nbar(:); Z = Z(:); mbar = mbar(:);
nZ = length(Z);
A = [ones(nZ, 1), nbar, nbar.^2, nbar.^3, nbar.*Z, nbar.^2.*Z, nbar.*Z.^2, Z, Z.^2, Z.^3];
b = mbar;
Avals = A\b;

9 件のコメント

Sergiusz Lorys
Sergiusz Lorys 2017 年 3 月 8 日
Thank you very much! Now I will do my best to understand how it works.
Walter Roberson
Walter Roberson 2017 年 3 月 8 日
This is a variation on constructing a Vandermonde matrix
Sergiusz Lorys
Sergiusz Lorys 2017 年 3 月 9 日
Ok, I think I get it in mathematically way, but still I have some doubts in the script way. Is the first line "nbar = nbar(:); Z = Z(:); mbar = mbar(:);" necessary? When I already have my data as a one line/bar matrix?
Walter Roberson
Walter Roberson 2017 年 3 月 9 日
That first line is needed if the data is not already a column vector. It is most common for the data to be in the form of row vectors. With the (:) in place the routine functions equally well whether the input is row or column vector, making it unnecessary for the user to think about that.
Sergiusz Lorys
Sergiusz Lorys 2017 年 3 月 12 日
Oh I get it now. Next is second line. Does it really matter which data I choose to make range of? Since every data has the same range? Then the A matrix. First argument is matrix of column of ones. Then next arguments are corresponding to my polynominal in one row. So I have the Vandermonde matrix. What is concerning me is final equation, A/b. In the Vandermonde matrix theory I see that A matrix should be inversed and multiplicated by b. So shouldn't that be b/A?
Walter Roberson
Walter Roberson 2017 年 3 月 12 日
If all of the variables are the same length, it does not matter which one you take length() of.
Be careful about writing A/b . The code I used was A\b which is not the same.
"If A is a square matrix, A\B is roughly equal to inv(A)*B, but MATLAB processes A\B differently and more robustly."
Sergiusz Lorys
Sergiusz Lorys 2017 年 3 月 13 日
I get it now! Can I ask you one more question? So now if I got my two variable function, and I will make 3D plot of it, what block should I use in simulink to make it read my M data from this graph with N and Z known?
Thank you very much for your help!
Walter Roberson
Walter Roberson 2017 年 3 月 13 日
Generally, you can use a From Workspace to read data in Simulink. However, Simulink does not read graphic objects, so you would have to calculate into variables instead.
Simulink generally works based on time steps, so you have to decide whether you are wanting to do these calculations and treat the results like constants for the Simulink session, or if you are wanting the values to be used somehow based upon input signals in Simulink. For example you might want to generate it all before Simulink and then use the calculated values as part of an N-D Lookup block (that is, interpolate based upon input values), or you might be looking to generate coefficients that are used in a Fcn (Arithmetic Block) or MATLAB Function Block... or you might be thinking of having Simulink read the values sequentially...
Sergiusz Lorys
Sergiusz Lorys 2017 年 3 月 13 日
Ok, I get it. Thank you very much again! I really appreciate that!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGeneral Applications についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by