Octave: Help with implementing midpoint rule

  • Thread starter Thread starter MaxManus
  • Start date Start date
  • Tags Tags
    Octave
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 4K views
MaxManus
Messages
268
Reaction score
1
I got the code from my textbook and it is supposed to work in matlab
Code:
function r = midpoint(a,b,f,n)
f = fcnchk(f);
h = (b-a)/n;
x = (a+h*0.5):h:(b-h*0.5);
y = feval(f,x);
r = h*sum(y(1:n));

The code fails on feval

I go tcnchk from wikipedia
Code:
function f=fcnchk(x, n)
  f = x;
end

and I use f = 'x.^2' as f

Can someone help me?
I don't know how to copy the error from Octave
 
Physics news on Phys.org