MATLAB: Error of binary operator ‘/’ not implemented for ‘scalar’ by ‘function handle’ operations

cellsfunction handlesmatricies

So I have been experimenting with function handles and generally trying to vectorise my code to make it run nice and fast. I have been trying to solve the forced KdV equation using a Newton-Raphson scheme and I have the basic code working with a simple example but I am having trouble with the odd error message in the title of this cry for help.
Anyone know what I should do?
I use matlab at work and Octave at home.

Best Answer

The weakly_nonlinear function includes these lines:
h=@eta;
while (sol_error>converge_limit)
F=-feval(h,x,sol,p,F,h,B,choice)';
This calls the eta function with @eta as the fifth input argument. Let's look at a chunk of eta:
function y=eta(x,f,p,F,h,B,choice)
N=length(x);
y=zeros(1,N+1);
rho=1;
g=9.81;
a_1=1-f(N+1);
a_2=0.75./h;
The last line is the one throwing the error. When computing a_2 you're dividing by @eta. That doesn't look right. Usually in this type of problem a variable named h represents the spacing between elements in x or something similar. If that's the case, you probably want to use diff(x) or something along those lines.