You made a good start, but there are several problems with your summation. You don't accumulate into your trapez variable, you don't use your index i in your function evaluation, you have your endpoints evaluated multiple times inside your loop, etc.
It would probably be best for you to code the logic up exactly as it appears in the formula. So, first do the summation. Then add the endpoints. Then multiply by (b-a)/n. Also, why not make your life simpler and use the same index variable k that is used in the formula? So, the outline would be this:
trapez = 0;
for k = 1: n - 1
trapez = trapez + calculateFormula(_____);
trapez = _____ + trapez + _____;
trapez = _____ * trapez;
Try to fill in the blanks above to see if you can get it to work. If you have more problems, come back and ask for more help with the specific problems you are having.