PDA

View Full Version : راهنمایی در متلب



pcpsoft
دوشنبه 19 اسفند 1392, 21: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.

pcpsoft
سه شنبه 20 اسفند 1392, 10:01 صبح
سلام دوستان من این کد ها رو تو متلب نوشتم اما اررور زیرو بهم میده مشکل از کجاست
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.

خواهش میکنم کمکم کنید باید امروز تحویلش بدم

rahnema1
سه شنبه 20 اسفند 1392, 20:30 عصر
من این دستور را دادم یه سری جواب داد

bisection("sin",-.1,.2,.001,1)

niloofar_f
جمعه 23 اسفند 1392, 13:13 عصر
تابع مربوط به به fnam چه عملی رو انجام میده؟
ایراد از این تابع هست، کد اون رو بررسی کنین!

matcode.ir
یک شنبه 25 اسفند 1392, 18:35 عصر
دوستان عزیز برای دریافت پاسخ های خود در مورد متلب به سایت زیر رجوع کنید :
http://www.matcode.ir

rahnema1
یک شنبه 25 اسفند 1392, 19:57 عصر
نمیشه جواب سوالها را همین جا بدین؟