Octave: Help with implementing midpoint rule

  • Thread starter Thread starter MaxManus
  • Start date Start date
  • Tags Tags
    Octave
Click For Summary
SUMMARY

The forum discussion centers on implementing the midpoint rule in Octave, specifically addressing an issue with the 'feval' function. The user provided a code snippet intended for MATLAB, which fails when executed in Octave. The user also referenced 'fcnchk' from Wikipedia but did not successfully implement it. The error encountered needs to be documented for further troubleshooting.

PREREQUISITES
  • Understanding of Octave syntax and functions
  • Familiarity with numerical methods, specifically the midpoint rule
  • Knowledge of function handles in Octave
  • Basic debugging skills in Octave
NEXT STEPS
  • Research how to use 'feval' correctly in Octave
  • Learn about function handles and their implementation in Octave
  • Explore error handling techniques in Octave to capture and report errors
  • Study the differences between MATLAB and Octave to ensure compatibility
USEFUL FOR

This discussion is beneficial for Octave users, students learning numerical methods, and developers transitioning from MATLAB to Octave who need to troubleshoot function-related issues.

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 12 ·
Replies
12
Views
7K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 7 ·
Replies
7
Views
4K