Homework Help: 4-point Gauss Quadrature with MATLAB

1. Dec 12, 2013

stvoffutt

1. The problem statement, all variables and given/known data
I need to evaluate a function using 4-point GQ.

2. Relevant equations
GQ theory

3. The attempt at a solution
I have got more of a programming issue in MATLAB. I am new to MATLAB. Actually this is for a numerical analysis course where we kind of learn MATLAB on the fly. First, I have 4 .m files to calculate the 4-point GQ which are listed below. Now, I have the program running for a specific function.m file and it calculates correctly. But I want to modify my existing GQ routine such that I can call any function.m file I want to. I think this is more of a syntax issue than anything. Since I have no experience with MATLAB any input or suggestions will be greatly appreciated.
.m files:

Main Program
format longe;

%fhandle = @integrand;
reference_weights = [0.3478548 0.6521452 0.6521452 0.3478548];
reference_nodes = [-0.861136312 -0.339981044 0.3399810436 0.8611363116];

---------------------------------------------------------------------------------------------
%This function takes the reference weights/nodes and transforms them to the [-1,1] interval

weights=1/2*(b-a)*reference_weights;
nodes = 1/2*((b-a)*reference_node+(b+a));
[weights, nodes]

---------------------------------------------------------------------------------------------
%Does the sum for GQ using nodes and weights

result = 0;
nn = length(New_weights); % We choose weights here instead of nodes because
% in multidemensions nodes is a matrix.
for j=1:nn
result = result + New_weights(j)*feval(fhandle,New_nodes(j));
end

---------------------------------------------------------------------------------------------
%example function

result = cos(pi/4*x)/sin(pi/4*x)^2;

---------------------------------------------------------------------------------------------

When I call the main function I get the following error:

Not enough input arguments.

Again, if I replace the loop sum by: