%function ff = noplates(xx)

heat=[ 30	0	10	    0.718	0.349;
       30	10  1e10	0.348	0.663;
       45	0	10	    0.718	0.349;
       45	10 	100	    0.4	    0.598;
       45	100	1e10	0.3	    0.663;
       50	0	20	    0.63	0.333;
       50	20	300	    0.291	0.591;
       50	300	1e10	0.13	0.732;
       60	0	20	    0.562	0.326;
       60	20	400	    0.306	0.529;
       60	400	1e10	0.108	0.703;
       65	0	20	    0.562	0.326;
       65	20	500	    0.331	0.503;
       65	500	1e10	0.087	0.718];

fric=[ 30	0	10	    50	    1;
       30	10	100	    19.4	0.589;
       30	100	1e10	2.99	0.183;
       45	0	15	    47	    1;
       45	15	300	    18.29	0.625;
       45	300	1e10	1.441	0.206;
       50	0	20	    34	    1;
       50	20	300	    11.25	0.631;
       50	300	1e10	0.772	0.161;
       60	0	40	    24	    1;
       60	40	400	    3.24	0.457;
       60	400	1e10	0.76	0.215;
       65	0	50	    24	    1;
       65	50	500	    2.8  	0.451;
       65	500	1e10	0.639	0.213];

    %***hot fluid***'
    mhot = 78.24;
    thotin = 50;
    thotout=19.2;
    rohot = 847;
    cphot=1900;

    %***cold fluid***'
    mcold = 86.94;
    tcoldin = 15.55;
    rocold = 847;
    cpcold=1900;

    %***Construction Data
    ea = 0.85;
    p = 0.005;       %Plate pitch
    s = 0.0006;       %Plate Thickness
    mu = 1.17;      %Enlargement Factor
    dport = 8*0.0254;   %Port Diameter
    w = 0.84;       %Effective Channal Wide
    lp = 2.18;      %Flow Length in one pass
    kwall = 20;
    pass = 2;
    angle = 30;

    n=400;

    %Mean channal flow area:
    b = p - s;
    %One channal flow area:
    Ax = b * w;
    %Channal equvalent diameter:
    de = 2 * b / mu;
    x = 0;
    cphott=cphot+100;
    cpcoldt=cpcold+100;
    while (abs(cphot - cphott) / cphot > 0.01) & (abs(cpcold - cpcoldt) / cphot > 0.01)
       cphot = cphott;
       cpcold = cpcoldt;
       q = mhot * cphot * abs(thotin - thotout);
       tcoldout = q / (mcold * cpcold) + tcoldin;
       tmeancold = (tcoldout + tcoldin) / 2;
       tmeanhot = (thotout + thotin) / 2;
       cphott = (4.2 * tmeanhot + 1805);
       cpcoldt = (4.2 * tmeancold + 1805);
    end

       muhot = (-8.333e-7 * tmeanhot ^ 3 + 0.002775 * tmeanhot ^ 2 - 0.3707 * tmeanhot + 18.25) * 10 ^ -6;
       mucold = (-8.333e-7 * tmeancold ^ 3 + 0.002775 * tmeancold ^ 2 - 0.3707 * tmeancold + 18.25) * 10 ^ -6;
       khot = (-0.0008 * tmeanhot + 1.4987) * 0.3048 ^ 2;
       kcold = (-0.0008 * tmeancold + 1.4987) * 0.3048 ^ 2;
       prhot = muhot * cphot / khot;
       prcold = mucold * cpcold / kcold;

       noplate=n+50;
       while abs(n-noplate)>1
                n=noplate;
                %Number of channals per pass:
                Nochannal = (n - 1) / (2 * pass);

                %***Heat transfer calculation***'
                Mdotchhot = mhot / Nochannal;
                Mdotchcold = mcold / Nochannal;

                %Mass velocity:
                mchhot = Mdotchhot / Ax;
                mchcold = Mdotchcold / Ax;

                %Reynolds number:
                rehot = mchhot * de / muhot;
                recold = mchcold * de / mucold;

                for Find = 1:14
                        if (angle == heat(Find, 1)) & (rehot >= heat(Find, 2)) & (rehot <= heat(Find, 3))
                                Chhot = heat(Find, 4);
                                yhot = heat(Find, 5);
                                Jhhot = Chhot * rehot ^ yhot;
                        end;
                        if (angle == heat(Find, 1)) & (recold >= heat(Find, 2)) & (recold <= heat(Find, 3))
                                Chcold = heat(Find, 4);
                                ycold = heat(Find, 5);
                                Jhcold = Chcold * recold ^ ycold;
                        end;
                 end;

                 for Find = 1:14
                        if (angle == fric(Find, 1)) & (rehot >= fric(Find, 2)) & (rehot <= fric(Find, 3))
                                kphot = fric(Find, 4);
                                zhot = fric(Find, 5);
                                fchhot = kphot / rehot ^ zhot;
                            end;
                        if (angle == fric(Find, 1)) & (recold >= fric(Find, 2)) & (recold <= fric(Find, 3))
                                kpcold = fric(Find, 4);
                                zcold = fric(Find, 5);
                                fchcold = kpcold / recold ^ zcold;
                            end;
                  end



                alfahot = Jhhot * khot * prhot ^ 0.33 / de;
                alfacold = Jhcold * kcold * prcold ^ 0.33 / de;

                rw = s / kwall;
                u = (1 / alfahot + 1 / alfacold + rw + 4.5 * 10 ^ -5) ^ -1;


             %if (abs(thotin - tcoldout) == abs(tcoldin - thotout))
              %          dtlm = abs(thotin - tcoldout);
              %     else
                        dtlm = ((thotin - tcoldout) - (thotout - tcoldin)) / (log((thotin - tcoldout) / (thotout - tcoldin)) / log(exp(1)));
                        %      end ;
             noplate=q/(u*ea*dtlm);
         end

             lch = pass * lp;
             dpchhot = (4 * fchhot * lch * mchhot ^ 2) / (2 * rohot * de);
             dpchcold = (4 * fchcold * lch * mchcold ^ 2) / (2 * rocold * de);

             mporthot = mhot / (pi / 4 * dport ^ 2);
             mportcold = mcold / (pi / 4 * dport ^ 2);
             dpphot = (1.3 * mporthot ^ 2) / (2 * rohot) * pass;
             dppcold = (1.3 * mportcold ^ 2) / (2 * rocold) * pass;

             dphot = dpphot + dpchhot;
             dpcold = dppcold + dpchcold;
%tcoldout;
%if (dphot>100000)|(dpcold>100000)
%    noplate=100000;
%end
%ff = noplate;
clc
disp('Number of Plates = ');disp(round(noplate*1.2))
disp('U = ');disp(round(u/1059*0.3048^2/1.8*3600))
disp('Temp of Hot in(F) = ');disp(round((thotin*1.8+32)))
disp('Temp of Hot out(F) = ');disp(round(10 * (thotout*1.8+32)) / 10)
disp('Temp of Cold in(F) =');disp(round(10 * (tcoldin*1.8+32)) / 10)
disp('Temp of Cold out(F) =');disp(round(10 * (tcoldout*1.8+32)) / 10)
disp('Hot Pressure Loss(psi)=');disp(round(dphot * 14.7 / 10000)/10)
disp('Cold Pressure Loss(psi)=');disp(round(dpcold * 14.7 / 10000)/10)
disp('dtlm(F) =');disp(round(10 * (dtlm*1.8)) / 10)
disp('Power(Btu/hr) =');disp(3600*round(q / 1059))
Number of Plates = 
   301

U = 
   789

Temp of Hot in(F) = 
   122

Temp of Hot out(F) = 
   66.6000

Temp of Cold in(F) =
    60

Temp of Cold out(F) =
  110.4000

Hot Pressure Loss(psi)=
    8.2000

Cold Pressure Loss(psi)=
   10.1000

dtlm(F) =
    8.8000

Power(Btu/hr) =
    15976800