\documentclass[a4,16pt]{book}
%\usepackage{mcode}
\usepackage{xepersian}
\begin{document}
\begin{lstlisting}[language=Matlab,                                                %
        basicstyle=\tt\small, numbers=left, frame=ltrb, framesep=5pt,   %
%        keywordstyle={\bf\textcolor{green}},                            %
%        stringstyle={\it\textcolor{red}},                               %
%        commentstyle={\textcolor{blue}},                                %
%        morekeywords={[2] TODO},        % to show TODO in alarming color
%        keywordstyle={[2]\color{red}\colorbox{cyan}}, % alarming colors!
%        % TODOs don't really work because they have to be *inside* comments, this is not vi :S
%        otherkeywords={..., =~},                                        %
        showspaces=false, showstringspaces=false, % not to mark spaces
        breaklines=true,                                                %
        upquote=true,   % for opening ` to show up as an inverted quote
        captionpos=t,                                                   %
        caption={تست},%
        label=vibrissaecode]
        
% Example Matlab code for calculating hypotenuse
function [a,agrad,ajac]=newton(h,b)
t1=h+b+10;t2=2272000/(h*b)+2*b+5; a=t1*t2;
if d==1
    agrad(1)=t2-t1*2272000/(h^2*b);
    agrad(2)=t2+t1*(-2272000/(h*b^2)+2);
    ajac(1,1)=2*(b+10)*2272000/(h^3*b);
    ajac(1,2)=2+10*2272000/(h^2*b^2);ajac(2,1)=ajac(1,2);
    ajac(2,2)=4+2*(h+10)*2272000/(h*b^3);
end
\end{lstlisting} 

\end{document}