- #1

- 265

- 0

## Homework Statement

I am to design a small piece of code in Mathematica that takes in four parameters, a number z, the number of intervals n, the starting point, and the ending point. We are basically integrate a function of the form:

[itex]f(x)=(z+1)x^{z}[/itex]

so we don't change the function at all except for the value of z.

## Homework Equations

The trapezoidal rule.

## The Attempt at a Solution

Here is my code so far, but my instructor is telling me that the calculated numbers/estimates are too high.

Code:

```
ClearAll["Global`*"]
trapRule[z_: 1, n_: 100, a_: 0, b_: 1] :=
Module[{h, end1, end2, total},
h = (b - a)/n;
end1 = (z + 1)*(a^z);
end2 = (z + 1)*(b^z);
total = h*(end1 + end2);
i = 1.;
While[i <= n,
total += 2*((z + 1)*((a + (i*h))^z));
i++;
];
(total*h)/2
]
```