Riemann Sum, need help explaining error in my code on my second day of matlab
7 views (last 30 days)
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
polevaluu is not a built-in MATLAB function. We would need to see the code for it.
Accepted Answer
Walter Roberson
on 20 Feb 2013
You are attempting to use polevaluu as a function that returns a value, but your line
function polevaluu(A,x)
is defined to mean that polevaluu does not return any value.
Possibly what you want is
function value = polevaluu(A,x)
3 Comments
Walter Roberson
on 20 Feb 2013
Your code for polevaluu is designed to "prints the value of the sum.". You probably do not want that. Change your line
value = sum(A)
to
value = sum(A);
notice the semi-colon
More Answers (0)
See Also
Categories
Find more on Logical 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!