Riemann Sum, need help explaining error in my code on my second day of matlab
Show older comments
So im trying to do a midpoint sum program for a class, and i am using the functions polevaluu and polint. these are similar to polyvalu and polyint.
so far:
function reimsum(v,a,b,n)
% v is a row vector, the coefficients of a decreasing order polynomial
%a and b are the lower and upper ends and n is # of subintervals
dx = (b-a)/n;
% set value for dx
C = zeros(1,n);
% skeleton for resulting values to be injected
for i=1:n ;
C(i)=(polevaluu(v,(a+(2*i-1))*dx))*2*dx
%the first element in C is equal to polevaluu(v, a+dx) times 2dx
% the second is equal to polevaluu(v, a+3dx) times 2dx
%each element is the area of a rectangle of the sum.
end
polevaluu(polint(v),b)-polevaluu(polint(v),a)
%exact value of integral
Sum(C)
%summation of areas of rectangles.
end
I am getting this error:
Error in ==> reimsum at 5 C(i)=(polevaluu(v,(a+(2*i-1))*dx))*2*dx
not sure exactly what it means, it's my second day using matlab.
Help anyone?
6 Comments
Walter Roberson
on 20 Feb 2013
What error message does it generate? For example does it say "Indices must be non-negative integers or logicals" ? Does it say "unknown function polevaluu"?
Campos
on 20 Feb 2013
Walter Roberson
on 20 Feb 2013
Yes, a screen shot would help.
Campos
on 20 Feb 2013
Walter Roberson
on 20 Feb 2013
polevaluu is not a built-in MATLAB function. We would need to see the code for it.
Campos
on 20 Feb 2013
Accepted Answer
More Answers (0)
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!