Octave: Help with implementing midpoint rule

  • Thread starter Thread starter MaxManus
  • Start date Start date
  • Tags Tags
    Octave
AI Thread Summary
The discussion revolves around a MATLAB code snippet intended for numerical integration using the midpoint rule. The user encounters an issue with the `feval` function, which fails to execute as expected. They mention using `fcnchk` from Wikipedia to define the function but are unsure if it is implemented correctly. The user attempts to pass a string representation of a function, 'x.^2', as the input for `f`. They seek assistance in resolving the error and are advised to copy the error message from Octave to provide more context for troubleshooting. The conversation highlights the need for clarity in function definitions and error reporting in MATLAB and Octave environments.
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
How about you look at the error and write it down, then post it here?
 

Similar threads

Replies
6
Views
3K
Replies
1
Views
2K
Replies
4
Views
2K
Replies
13
Views
2K
Replies
2
Views
3K
Replies
1
Views
2K
Replies
7
Views
3K
Replies
5
Views
4K
Back
Top