Evaluating a definite integral as the limit of a Riemann sum I'm having trouble evaluating the following problem using the limit of a Riemann sum:
$\int_1^4x^2-4x+2dx$
Using $\lim_{n->\infty}\sum_{i=1}^n f(x_i)\Delta x$ where $a=1$ and $b=4$, $\Delta x = \frac{b-a}{n}$, and $x_i = a + i\Delta x$,
I come up with:
$\lim_{n->\infty}\sum_{i=1}^n[\frac{(3i+n)^2}{n^2}-\frac{12i+4n}{n}+2][\frac{3}{n}]$
which I simplify:
$\lim_{n->\infty}\sum_{i=1}^n[\frac{27i^2+18ni+3n^2}{n^3}-\frac{36i+12n}{n^2}+\frac{6}{n}]$
$\lim_{n->\infty}\sum_{i=1}^n[\frac{27i^2+18ni+3n^2}{n^3}-\frac{36ni+12n^2}{n^3}+\frac{6n^2}{n^3}]$
$\lim_{n->\infty}\sum_{i=1}^n[\frac{27i^2-18ni-3n^2}{n^3}]$
$\lim_{n->\infty}\sum_{i=1}^n\frac{27i^2}{n^3}-\sum_{i=1}^n\frac{18i}{n^2}-\sum_{i=1}^n\frac{3}{n}$
$\lim_{n->\infty}\frac{27}{n^3}\sum_{i=1}^ni^2-\frac{18}{n^2}\sum_{i=1}^ni-\frac{3}{n}\sum_{i=1}^n1$
$\lim_{n->\infty}[\frac{27}{n^3}][\frac{n(n+1)(2n+1)}{6}]-[\frac{18}{n^2}][\frac{n(n+1)}{2}]-[\frac{3}{n}]$
which renders $\lim_{n->\infty}\frac{15n+9}{2n^2}$ which is $0$.
The integral evaluates to $-3$, so I know I have made a mistake or more, however I've checked my arithmetic several times each step and can't find the error, so unless my brain is fried, I must have made a mistake in step.

Wow this confused me for a bit also until I realized we were both making the same mistake. In your case, you wrote
$$\sum_{i=1}^n\frac3n=\frac3n\sum_{i=1}^n1=\frac3n,$$
but $\sum_{i=1}^n1=n$ and this should have been
$$\sum_{i=1}^n\frac3n=\frac3n\sum_{i=1}^n1=3.$$

Since $x_i=1+\frac{3i}{n}=\frac{n+3i}{n}$, the sum is
\begin{align}
\sum_{i=1}^nf\left(\frac{n+3i}{n}\right)\left(\frac3n\right)&=\sum_{i=1}^n\left(\frac{(n+3i)^2}{n^2}-4\frac{n+3i}{n}+2\right)\left(\frac3n\right)\\ \\
&=\sum_{i=1}^n \left(\frac{27i^2}{n^3}-\frac{18i}{n^2}-\frac{3}{n}\right) \\ \\
&=\frac{27}{n^3}\sum_{i=1}^n(i^2)-\frac{18}{n^2}\sum_{i=1}^n(i)-\sum_{i=1}^n\frac3n\\ \\
&=\frac{27}{n^3}\left(\frac{n(n+1)(2n+1)}{6}\right)-\frac{18}{n^2}\left(\frac{n(n+1)}{2}\right)-3\\ \\
&=\frac{9}{2n^2}+\frac{3}{2n}-3.
\end{align}
As $n\to\infty$, the sum approaches $-3$.
