\documentclass[a4,16pt]{book}
\usepackage{color}
\usepackage{listings}
\usepackage{xepersian}

\makeatletter
\renewcommand\lstlistingname{\if@RTLmain برنامه\else Listings\fi}
\long\def\@makecaption#1#2{%
   \vskip\abovecaptionskip
   \sbox\@tempboxa{#1: #2}%
   \ifdim \wd\@tempboxa >\hsize
     \if@RTLmain\beginR\fi#1: #2\if@RTLmain\endR\fi\par
   \else
     \global \@minipagefalse
     \hb@xt@\hsize{\if@RTLmain\beginR\fi\hfil\box\@tempboxa\hfil\if@RTLmain\endR\fi}%
   \fi
   \vskip\belowcaptionskip}%

\makeatother

\def\lstlistingname{\if@RTL برنامه‌ی\else برنامه‌ی\fi}
\def\lstlistlistingname{\if@RTL فهرست برنامه‌ها\else فهرست برنامه‌ها\fi}


\begin{document}



\lstset{
language=Matlab,
frame=trBL, 
% backgroundcolor=\color{yellow},
numbers=left,
numberstyle=\scriptsize,
frameround=fttt,
showspaces=false,           % Leerzeichen anzeigen ?
showtabs=false,             % Tabs anzeigen ?
xleftmargin=17pt,
framexleftmargin=17pt,
framexrightmargin=5pt,
framexbottommargin=4pt,
%backgroundcolor=\color{lightgray},
showstringspaces=false ,
breaklines=true,
texcl=true,
basicstyle=\footnotesize\ttfamily,
  commentstyle= \color{green},
  keywordstyle=\bfseries\color{red},
  stringstyle=\color{blue},
}  

%  
 




\begin{LTR}
\begin{lstlisting}[caption=\rl{یک برنامه نمونه}, label={Pr-1}] 
% 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{LTR}
\end{document}