0

I want to solve for coefficients {c1,c2,...cn} based on the following relationship: enter image description here

Where the N by N matrix B is a set of monomial basis {1,x,x^2,x^3,....x^n} and fa(x) is the approximation function. If I want to loop through n = [3,10,20,50] and given that xj = 1/2*5-1/2*3*cos(j*pi/n) (Chebyshev point distribution), how should I create such a matrix B using NumPy?

1 Answers1

0

It looks like the b's are functions, that would be powers of x

b0 = 1
b1 = x
b2 = x^2
b3 = x^3
...

And you are trying to find the best coefficients c_n to fit the function f(x)

You simply have to choose a set of x values. Say, you want to do the approximation within the range -1 to +1. Choose values of xx such as x0 = -1.0, x1 = -0.9 , -0.8 , -0.7 ..., 0.9 , 1.0

x = np.arange(-1,1, 0.1)

Each line in B array are the x^n values for each of these xi values.

You have to decide to what power you want your polynomial. Perhaps the easiest way is to create a y space with the "exponent", example going from x^0 to x^5. ' y=np.arange(0,6) '

And then use the "meshgrid trick"

y_mg , x_mg = np.meshgrid (y, x)

#For each value of x_mg and y_mg, use numpy arithmetic
B = numpy.power(x_mg , y_mg)
Luis
  • 26
  • 9