Hi all,
I try to calculate this function
$3x^{2} + x + 1$
But, I get the result different from the solution:
This is the code I use:
using CalculusWithJulia
function riemann(f, a, b, n; method="right")
xs = a:(b-a)/n:b
deltas = diff(xs) # forms x2-x1, x3-x2, ..., xn-xn-1
if method == "left"
cs = xs[1:end-1]
elseif method == "right"
cs = xs[2:end]
else
cs = [(xs[i] + xs[i+1])/2 for i in 1:length(deltas)]
end
sum(f(cs[i]) * deltas[i] for i in 1:length(deltas))
end
# intervals
a, b = -1,1
# the function
f(x) = 3x^2 + x + 1
#number of partitions
n = 10
# print the result
println("The area for $f(x):")
riemann(f, -1, 1, 10) # Same result
the result from the code is: 4.24
different from the solution 4.656. Maybe the solution is wrong?