- #1
renolovexoxo
- 25
- 0
Here is the code I have, but I keep getting the error message: Undefined function 'f' for input arguments of type 'double'.
I don't know what I have that is causing this. Does anybody see what's wrong with my code?
MaxIt = 1000;
epsilon = 10^-5;
a=1;
b=2;
c = (b+a)/2;
NumIt = 0;
while NumIt< MaxIt && abs(f(c))>epsilon
if f(a)*f(c) < 0
b = c;
else
a = c;
end
NumIt = NumIt + 1;
c = (b+a)/2;
end
end
function y = f(x)
y = exp(x)-2^-x+2*cos(x)-6;
end
Undefined function 'f' for input arguments of type 'double'.
I don't know what I have that is causing this. Does anybody see what's wrong with my code?
MaxIt = 1000;
epsilon = 10^-5;
a=1;
b=2;
c = (b+a)/2;
NumIt = 0;
while NumIt< MaxIt && abs(f(c))>epsilon
if f(a)*f(c) < 0
b = c;
else
a = c;
end
NumIt = NumIt + 1;
c = (b+a)/2;
end
end
function y = f(x)
y = exp(x)-2^-x+2*cos(x)-6;
end
Undefined function 'f' for input arguments of type 'double'.