disp (' Welcome') disp (' ') disp (' This is the general program for Interpolating ') disp (' ') disp (' This program have beean writen by Ali Ashouri') disp (' ') disp (' ') disp (' choose your used method:') disp (' ') disp (' Lagranje') disp (' Newton') disp (' ') R=char(input(' which one method do you want to use and insert it as char? ')); switch R case 'Lagranje' disp (' This is the code of Lagranje method.Is writen by Ali Ashouri') disp (' ') disp (' ') syms x; n=input(' Enter your number of data of xi or fi (n) : '); n=n+1; y=cell(1,n); f=cell(1,n); for i=1:n b=input(' Enter your data of xi : '); c=input(' Enter your data of fi : '); y(1,i)={b}; f(1,i)={c}; end; disp (' ') disp([' xi : ',y]) disp([' fi : ',f]) P=0; for i=1:n U=1; Q=1; for j=1:n if i==j else U=U.*(x-cell2mat(y(1,j))); Q=Q*(minus(cell2mat(y(1,i)),cell2mat(y(1,j)))); end; end; P=P+mtimes(U./Q,cell2mat(f(1,i))); end; r=[' P(x) : ',P]; disp(r); u=input(' Enter your data of x : '); T=subs(P,x,u); disp(' ') disp([' The fi of your x is : ',num2str(sym2poly(T))]); case 'Newton' disp (' This is the code of Newton method.Is writen by Ali Ashouri') disp (' ') disp (' ') syms x; n=input(' Enter your number of data of xi or fi (n) : '); n=n+1; y=cell(1,n); f=cell(1,n); Z=cell(n-1,n-1); for i=1:n b=input(' Enter your data of xi : '); c=input(' Enter your data of fi : '); y(1,i)={b}; f(1,i)={c}; end; for i=1:n-1 for j=1:n-1 Z(i,j)={0}; end; end; disp (' ') disp([' xi : ',y]) disp([' fi : ',f]) for j=1:n-1 Z(j,1)={(cell2mat(f(1,j+1))-cell2mat(f(1,j)))./(cell2mat(y(1,j+1))-cell2mat(y(1,j)))}; end; for i=2:n-1 for j=1:n-i Z(j,i)={(cell2mat(Z(j+1,i-1))-cell2mat(Z(j,i-1)))./(cell2mat(y(1,j+i))-cell2mat(y(1,j)))}; end; end; Q=0; disp(Z) for i=1:n-1 U=1; for j=1:i U=U.*(x-cell2mat(y(1,j))); end; U=U.*(cell2mat(Z(1,i))); Q=Q+U; end; P=Q+cell2mat(f(1,1)); r=[' P(x) : ',P]; disp(r); u=input(' Enter your data of x : '); T=subs(P,x,u); disp(' ') disp([' The fi of your x is : ',num2str(sym2poly(T))]); otherwise disp('your method is incorrect'); end;