I have a problem that is very simple in concept but very difficult to actually solve.
I need to find the best fit polynomial of degree at most 4 for f(x)=ln(x) on the interval [1,4].
So far I have gotten to the point where I need to solve the system of equations: $0=-3a_0-\frac{15a_1}{2}-21a_2-\frac{255a_3}{4}-\frac{1023a_4}{5}-3+ln\left(256\right),\\0=-\frac{15a_0}{2}-21a_1-\frac{255a_2}{4}-\frac{1023a_3}{5}-\frac{1365a_4}{2}-\frac{15}{4}+8ln\left(4\right),\\0=-21a_0-\frac{255a_1}{4}-\frac{1023a_2}{5}-\frac{1365a_3}{2}-\frac{16383a_4}{7}-7+\frac{64}{9}ln\left(64\right),\\0=-\frac{255a_0}{4}-\frac{1023a_1}{5}-\frac{1365a_2}{2}-\frac{16383a_3}{7}-\frac{65535a_4}{8}-\frac{255}{16}+64ln\left(4\right),\\0=-\frac{1023a_0}{5}-\frac{1365a_1}{2}-\frac{16383a_2}{7}-\frac{65535a_3}{8}-29127a_4-\frac{1023}{25}+\frac{1024ln\left(4\right)}{5}$
I know how to do this in theory, but the execution is incredibly tedious and errors easily find their way in. I was wondering if anyone knew a good system of equation calculator, symbolab seems to only be able to solve up to 4 terms, or code for solving a 5 term system of equations on matlab.


There are a number of ways to do it. You must specify exactly what you mean by 'the best fit polynomial', but to solve the system of equations you provided you can simply hard code it:
I don't know exactly what the $a_i$ terms mean in your equation, but this is how you get them. You should be more clear on how you derived this system of equations, so the code calculates the coefficient matrix by itself, without entering the matrix by hand.
I warn you, however, there are other ways to obtain a curve fitting in MATLAB.
Polynomial fit:
If your polynomial has the form
$ p(x)=a_4x^4+a_3x^3+a_2x^2+a_1x+a_0 $
then you have 5 unkowns. Provided you have your function evaluated in 5 points, you can solve for the 5 unkowns rearrangin the above equation in a matrix form:
$ \begin{bmatrix} x_1^4 & x_1^3 & x_1^2 & x_1 & 1 \\ x_2^4 & x_2^3 & x_2^2 & x_2 & 1 \\ x_3^4 & x_3^3 & x_3^2 & x_3 & 1 \\ x_4^4 & x_4^3 & x_4^2 & x_4 & 1 \\ x_5^4 & x_5^3 & x_5^2 & x_5 & 1 \\ \end{bmatrix} \begin{Bmatrix} a_4\\a_3\\a_2\\a_1\\a_0 \end{Bmatrix}= \begin{Bmatrix} \log(x_1)\\\log(x_2)\\\log(x_3)\\\log(x_4)\\\log(x_5) \end{Bmatrix} $
Perhaps this was what you tried to do? You can automatically code it as:
This returns the coefficients of the polynomial as defined above. You can do it automatically, however, using a MATLAB proper function.
The function polyval does a polynomial curve fitting in a least-squares sense. If you want the exact interpolation for a 4th order polynomial, then you should provide it with 5 points:
The array
phas the polynomial coefficients of the curve fit. You can evaluate the polynomial with the polyval function. Notice this generates the same polynomial coefficients as calculated above with the backlash operator.If you provide more points than the necessary, MATLAB's
polyfitfunction will find the best polynomial in a least squares sense.The nodes don't necessarily must be evenly spaced. As a matter of fact, you can use the Chebyshev nodes to minimize the effect of Runge's phenomenon.