1

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.

David
  • 27
  • 3

1 Answers1

2

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.

Derek Brown
  • 4,232
  • 4
  • 27
  • 44
  • So that would yield a matrix values that would fit the data. How would I make that best fit be a function of x? – David Oct 16 '17 at 01:57
  • 1
    The resultant matrix represents a function of x. For instance, if I were to get [1, 2, 3, 4] as a result, this would be x^3 + 2x^2 + 3x + 4. – Derek Brown Oct 16 '17 at 01:59