pcpsoft
دوشنبه 19 اسفند 1392, 22:17 عصر
سلام دوستان من این کد ها رو تو متلب نوشتم اما اررور زیرو بهم میده مشکل از کجاست
function root = bisection(fname,a,b,delta,display)
% The bisection method.
%
%input: fname is a string that names the function f(x)
% a and b define an interval [a,b]
% delta is the tolerance
% display = 1 if step-by-step display is desired,
% = 0 otherwise
%output: root is the computed root of f(x)=0
%
fa = feval(fname,a);
fb = feval(fname,b);
if sign(fa)*sign(fb) > 0
disp('function has the same sign at a and b')
return
end
if fa == 0,
root = a;
return
end
if fb == 0
root = b;
return
end
c = (a+b)/2;
fc = feval(fname,c);
e_bound = abs(b-a)/2;
if display,
disp('');
disp(' a b c f(c) error_bound');
disp('');
disp([a b c fc e_bound])
end
while e_bound > delta
if fc == 0,
root = c;
return
end
if sign(fa)*sign(fc) < 0 % a root exists in [a,c].
b = c;
fb = fc;
else % a root exists in [c,
a = c;
fa = fc;
end
c = (a+b)/2;
fc = feval(fname,c);
e_bound = e_bound/2;
if display, disp([a b c fc e_bound]), end
end
root = c;
Error using myfun (line 11)
Not enough input arguments.
function root = bisection(fname,a,b,delta,display)
% The bisection method.
%
%input: fname is a string that names the function f(x)
% a and b define an interval [a,b]
% delta is the tolerance
% display = 1 if step-by-step display is desired,
% = 0 otherwise
%output: root is the computed root of f(x)=0
%
fa = feval(fname,a);
fb = feval(fname,b);
if sign(fa)*sign(fb) > 0
disp('function has the same sign at a and b')
return
end
if fa == 0,
root = a;
return
end
if fb == 0
root = b;
return
end
c = (a+b)/2;
fc = feval(fname,c);
e_bound = abs(b-a)/2;
if display,
disp('');
disp(' a b c f(c) error_bound');
disp('');
disp([a b c fc e_bound])
end
while e_bound > delta
if fc == 0,
root = c;
return
end
if sign(fa)*sign(fc) < 0 % a root exists in [a,c].
b = c;
fb = fc;
else % a root exists in [c,
a = c;
fa = fc;
end
c = (a+b)/2;
fc = feval(fname,c);
e_bound = e_bound/2;
if display, disp([a b c fc e_bound]), end
end
root = c;
Error using myfun (line 11)
Not enough input arguments.