- #1

- 1,993

- 107

I have a question that I have not been able to find. The below function accepts outside scalar inputs but not vectors. The code is below.

Also, ## a, b, delta,FA,Hi,vHnew,iv## are all scalars defined outside the function. The vector I would like to add as an input is ##x##, which I've commented below what it could be. However, even if I add this to the function line and ##fa, fb##, and ##fc##, along with the ##fx## function at the end, I still receive "Error Not enough input arguments." Please help me so this function can operate on ##x## when it is defined outside the function.

Any help is greatly appreciated!

Code:

```
function c = mshvol(a, b, delta,FA,Hi,vHnew,iv)
fa = f(a,FA,Hi,vHnew,iv);
fb = f(b,FA,Hi,vHnew,iv);
while ( abs(b - a) > 2*delta )
c = (b + a)/2;
fc = f(c,FA,Hi,vHnew,iv);
if sign(fc) ~= sign(fb)
a = c; fa = fc;
else
b = c; fb = fc;
end% end if
end
function fx = f(zbulk,FA,Hi,vHnew,iv)
dx=.001;
% x=0:dx:5;
y=25-x.^2;
diff = abs(x-zbulk);
[~, idx] = min(diff); %index of closest value
z=y(idx:end);
fx = zbulk*15+trapz(z)*dx-70; %% Volume balance
return;
```