function [kx,ky]=Stretching_Function(I,J,I_lead_edge,JL,Dx,Dy,del_y_min,del_x_min)

%THE INPUT PARAMETERS ARE
%Dy  Dx    %Total distance away from foil is 50 chord lengths
%JL  IL    %The maximum y index;  The maximum for the x stretch
%J   I     %The starting value for y and x in the stretch

%%The Stretching Function for our grid is given by 
%
%   y=D*(e^k((J-1)/(JL-1))-1)/(e^k-1);
%
%We're trying to solve for the value of k where 
%
%   f(k)=del_y_min-y2=0
%
%Using Newton's Method
c=1;                                         %The minimum distance unit
J_fac=(J-1)/(JL-1);                          %The value in the y exponent
I_fac=(I-1)/(I_lead_edge-1);               %The value in the x exponent

%Use Newton's Method to find this root
%FIRST FOR THE Y DIRECTION------STRETCHED FROM J=1 to JL=51
%Minimize f(k)=del_y_min-y_2

ky=1;
for i=1:12
    f=del_y_min-Dy*(exp(ky*J_fac)-1)/(exp(ky)-1);
    f_prime=-Dy*((exp(ky)-1)*J_fac*exp(ky*J_fac)-(exp(ky*J_fac)-1)*exp(ky))/(exp(ky)-1)^2;
    ky=ky-f/f_prime;
    
end

%SECOND FOR THE X DIRECTIOn----STRETCHED FROM I=37 to IL=51

kx=1;
for i=1:10
    f=del_x_min-Dx*(exp(kx*I_fac)-1)/(exp(kx)-1);
    f_prime=-Dx*((exp(kx)-1)*I_fac*exp(kx*I_fac)-(exp(kx*I_fac)-1)*exp(kx))/(exp(kx)-1)^2;
    kx=kx-f/f_prime;

end
