Riemann Sum, need help explaining error in my code on my second day of matlab
Afficher commentaires plus anciens
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 commentaires
Walter Roberson
le 20 Fév 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
le 20 Fév 2013
Walter Roberson
le 20 Fév 2013
Yes, a screen shot would help.
Campos
le 20 Fév 2013
Walter Roberson
le 20 Fév 2013
polevaluu is not a built-in MATLAB function. We would need to see the code for it.
Campos
le 20 Fév 2013
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Linear Algebra dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!