روش سکانت ( Secant ) دانلود رمز فایل : AliAshouri
disp (' This is the code of Secant method.Is writen by Ali Ashouri')
disp (' ')
disp (' ')
disp (' ********Before enter anything read all of introduction that will write. read all of them*******')
disp (' ')
format long
disp (' x must be at double class and before play the program write its limit in commond window. like: x=-1:0.00001:1')
disp (' ')
disp (' function should be start by @(x) like : @(x) sin(x)')
disp (' ')
f=input('enter your function : ');
x1=input('enter the x1 number : ');
x0=input('enter the x0 number : ');
disp(' ')
disp(' ')
disp (' choose one of the model for stoping criterion and input as char:')
disp (' abs(f(xn))<=eps abs(f(xn))=P eps=d')
disp (' abs(xn-x0)<=eps abs(xn-x0)=P eps=d')
disp (' ')
disp (' ')
P=input('choose P as char: ');
d=input('enter the epsilon number : ');
tic
double (x);
n=1;
xn=(x1-(f(x1)*(x1-x0))/(f(x1)-f(x0)));
disp('n I x0 I x1 I xn I f(xn)')
disp ------------------------------------------------------------------------------------------------------------------------------------
r=[num2str(n),' I ',num2str(x0),' I ',num2str(x1),' I ',num2str(xn),' I ',num2str(f(xn))];
disp (r)
switch P
case 'abs(f(xn))'
while abs(f(xn))>=d
x0=x1;
x1=xn;
xn=(x1-(f(x1)*(x1-x0))/(f(x1)-f(x0)));
n=n+1;
r=[num2str(n),' I ',num2str(x0),' I ',num2str(x1),' I ',num2str(xn),' I ',num2str(f(xn))];
disp (r)
end;
case 'abs(xn-x0)'
while abs(xn-x0)>=d
x0=x1;
x1=xn;
xn=(x1-(f(x1)*(x1-x0))/(f(x1)-f(x0)));
n=n+1;
r=[num2str(n),' I ',num2str(x0),' I ',num2str(x1),' I ',num2str(xn),' I ',num2str(f(xn))];
disp (r)
end;
otherwise
disp (' your model choice is incorrect')
end;
n=n+1;
disp (' ')
disp ([' c= ',num2str(xn)])
disp ([' n= ',num2str(n)])
toc;