matlabmatrixbest-fit-curve

Curve fitting a Matrix


Hey everyone I feel like I have a basic question that for some reason I can't figure out

So I have a matrix:

A = [1.7764,1.7677,1.7509,1.7352,1.7075,1.6715,1.6043l,1.5199,1.4210,1.3041,1.1756,1.0270,0.8582,0.6910,0.5493,0.3968,0.2187 ];

So I want to a find a function for A using a best fit curve. I know I want to use some kind of:

polyfit(A)

I have never needed to find an equation of a matrix and im sure it will be a simple one line code that I've been stuck on for longer than I care to admit.

If more information is needed please let me know.


Solution

  • In order to find a polyfit, you need to define a vector for the x-axis against which you are going to plot. For instance:

    A_y = [1.7764,1.7677,1.7509,1.7352,1.7075,1.6715,1.6043l,1.5199,1.4210,1.3041,1.1756,1.0270,0.8582,0.6910,0.5493,0.3968,0.2187 ];
    A_x = 1:length(A_y);
    polyfit(A_x, A_y, <Degree>);
    

    Note that you need to substitute <Degree> with the degree of the fit you are looking for.