compiled learning tasks

Upload: marineil-gomez

Post on 07-Apr-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/4/2019 Compiled Learning Tasks

    1/17

    BIO176/A1

    Learning TasksCOMPILATION

    Submitted by:

    Gomez, Marineil C.2008102730

    Submitted to:Prof. Allan Soriano

  • 8/4/2019 Compiled Learning Tasks

    2/17

    Learning Task 1

    Syntax:

    %Evaluate this string in the base work-

    space

    %Evaluate this string in the base work-

    space

    close all

    clear

    clc

    %Header;disp(['Homework 1']);

    disp(['Pressure-Volume Graph of Carbon

    Tetrachloride using Peng-Robinson Equa-

    tion of State']);

    disp(['Gomez, Marineil C.']);

    disp(['2008102730']);

    %define variables;

    syms Vp

    syms P1p P2p P3p;

    Pcp=45.6;%Pcp in bar;

    Tcp=556.4;

    %Tcp in K;

    wp=0.194;

    Rp=8.31451*10^(-5);

    %Rp in bar m3/mol K;

    Vcp=0.276*10^3;

    %Vcp in m3/mol;

    Tr1p=0.5;

    Tr2p=1.0;Tr3p=1.5;

    T1p=Tr1p*Tcp;

    T2p=Tr2p*Tcp;

    T3p=Tr3p*Tcp;

    kp=0.37464+1.54226*wp-0.26992*(wp^2);

    rAt1p=1+kp*(1-sqrt(Tr1p));

    rAt2p=1+kp*(1-sqrt(Tr2p));

    rAt3p=1+kp*(1-sqrt(Tr3p));

    At1p=rAt1p^2;

    At2p=rAt2p^2;

    At3p=rAt3p^2;

    a1p=0.45724*(Rp^2)*(Tcp^2)*(At1p/Pcp);

    a2p=0.45724*(Rp^2)*(Tcp^2)*(At2p/Pcp);

    a3p=0.45724*(Rp^2)*(Tcp^2)*(At3p/Pcp);

    bp=0.0778*((Rp*Tcp)/Pcp);

    Vp=0.01:0.001:300;

    %substitute for equation;

    P1p=PengRobinson1(Rp,T1p,Vp,a1p,bp);

    P2p=PengRobinson2(Rp,T2p,Vp,a2p,bp);

    P3p=PengRobinson3(Rp,T3p,Vp,a3p,bp);

    %Graph of function;

    G1p=semilogx(Vp,P1p,'b.');

    xlabel('{\it V}, m^3/mol')

    ylabel('{\it P}, bar')

    title('{\it Pressure} vs{\it Volume} us-

    ing Peng Robinson EOS')

    text(1e-3,150,'Carbon Tetrachloride

    (CCl4)','EdgeColor','green',...

    'LineWidth',3,'FontSize',12, ...

    'BackgroundColor',[.7 .9 .8])

    axis ([0 400 -0.1 3]);

    hold on

    G2p=semilogx(Vp,P2p,'r.');

    hold on

    G3p=semilogx(Vp,P3p,'g.');

    legend('Tr = 0.5','Tr = 1.0','Tr =

    1.5',1)

    hold on

    Instructions: Plot Pvs Vfor carbon tetrachloride (CCl4) at temperatures Tr= 0.5, 1.0 and 1.5 based

    on the Peng-Robinson Equation of State

  • 8/4/2019 Compiled Learning Tasks

    3/17

    M-File:

    function [ P1p ] = PengRobinson1(Rp,T1p,Vp,bp,a1p)%PENGROBINSON1 Summary of this function goes here% Detailed explanation goes hereP1p=((Rp*T1p)./(Vp-bp))-(a1p./(Vp.^2+2*Vp.*bp-bp^2));

    End

    function [ P2p ] = PengRobinson2( Rp,T2p,Vp,bp,a2p)%PENGROBINSON2 Summary of this function goes here% Detailed explanation goes hereP2p=((Rp*T2p)./(Vp-bp))-(a2p./(Vp.^2+2*Vp.*bp-bp^2));

    end

    function [ P3p ] = PengRobinson3( Rp,T3p,Vp,bp,a3p )%PENGROBINSON3 Summary of this function goes here% Detailed explanation goes hereP3p=((Rp*T3p)./(Vp-bp))-(a3p./(Vp.^2+2*Vp.*bp-bp^2));

    end

  • 8/4/2019 Compiled Learning Tasks

    4/17

    File Viewer

  • 8/4/2019 Compiled Learning Tasks

    5/17

    Learning Task 2

    Syntax:

    %calculations;

    %input parameters;

    mudCCl4= 0; % dipole moment in debye, ppt

    4 slide 60 ;

    mudHCl=1.08; % dipole moment in debye.

    ppt 4 slide 60 ;

    muCCl4=mudCCl4*3.33569e-30; %convert de-

    bye;muHCl=mudHCl*3.33569e-30; %convert debye;

    alphaCCl4=10.5e-30; %polarizability in

    m3;

    alphaHCl=2.6e-30; %polarizability in m3;

    iVCCl4=11; %ionization potential in eV;

    iVHCl=12.8; %ionization potential in eV;

    iCCl4=iVCCl4*1.60218e-19; %conv eV to J

    iHCl=iVHCl*1.60218e-19; %conv eV to J

    Eo=8.85419e-12; % dielectric permitivity

    in vacuum in C^2/J-m;

    T=373.15; % temperature (100oC) in K;

    kboltz=1.3807e-23; % Boltzman constant in

    J/K;

    r=[5e-10 10e-10 50e-10 100e-10]; % dis-

    tances in m;

    disp(['dielectric permitivity in vacuum

    (Eo) = ', num2str(Eo),' C^2/J-m']);

    disp(['Boltzman Constant = ', num2str

    (kboltz),' J/K']);

    disp(['Temperature = ', num2str(T),'K']);

    disp(['distances (r) = [5 10 50 100] Ang-

    strom']);

    disp(['For CCl4:']);disp([' dipole moment = ', num2str

    (mudCCl4),' debye']);

    disp([' polarizability = 10.5e-30 m3']);

    disp([' first ionization potential = ',

    num2str(iVCCl4),' eV']);

    disp(['For HCl:']);

    disp([' dipole moment = ', num2str

    (mudHCl),' debye']);

    disp([' polarizability = 2.6e-30 m3']);

    disp([' first ionization potential = ',

    num2str(iVHCl),' eV']);

    %calculation using eq 4-8 for dipole-

    dipole interactions;

    E=4*pi*Eo;

    k=(E^2)*kboltz*T;

    x=-(2*(muCCl4^2)*(muHCl^2))/(3*k); %

    collation of constants;

    gpolar=x./(r.^6); %mean potential energy;

    %calculation using eq 4-14 for induced

    dipole interactions;

    n=(alphaCCl4*(muHCl^2))+(alphaHCl*

    (muCCl4^2));

    ginduced=(-n/(E^2))./(r.^6);

    %calculation using eq 4-18 for dispersion

    interactios;

    ion=(iHCl*iCCl4)/(iHCl+iCCl4);

    y=(-3/2)*((alphaHCl*alphaCCl4)*ion)/

    (E^2);

    gdisperse=y./(r.^6);

    %graphics diplay;

    %table output;

    gamma=cell(5,4);

    gamma{1,1}='Distance';

    gamma{1,2}='Polar/Polar';

    gamma{1,3}='Polar/Induction';

    gamma{1,4}='Dispersion';

    gamma{2,1}='5 Angstrom';gamma{3,1}='10 Angstrom';

    gamma{4,1}='50 Angstrom';

    gamma{5,1}='100 Angstrom';

    gamma{2,2}=num2str(gpolar(1));

    gamma{3,2}=num2str(gpolar(2));

    gamma{4,2}=num2str(gpolar(3));

    gamma{5,2}=num2str(gpolar(4));

    Instructions: Calculate the intermolecular potentials: polar/polar, polar/induction, dispersion at 100C

    and for distances 5, 10, 50 100 A for the pair-molecules CCl 4/HCl

  • 8/4/2019 Compiled Learning Tasks

    6/17

    gamma{2,3}=num2str(ginduced(1));

    gamma{3,3}=num2str(ginduced(2));

    gamma{4,3}=num2str(ginduced(3));

    gamma{5,3}=num2str(ginduced(4));

    gamma{2,4}=num2str(gdisperse(1));

    gamma{3,4}=num2str(gdisperse(2));

    gamma{4,4}=num2str(gdisperse(3));

    gamma{5,4}=num2str(gdisperse(4));

  • 8/4/2019 Compiled Learning Tasks

    7/17

    File Viewer

  • 8/4/2019 Compiled Learning Tasks

    8/17

    Learning Task 3

    Syntax:

    For Lennard-Jones Potential

    %input data;

    Na=6.02214e23; %Avogadros number in part/

    mol;

    sLJ=5.711e-8; %in cm;eKLJ=233.28; %in K;

    %data from table 5-1 praustnitz 1999;

    %calculations;

    B1=((2*pi)/3)*Na*(sLJ^3); %from ppt 5

    slide 76;

    kTeLJ=0.3:0.01:5;

    kToeLJ=kTeLJ(iLJ);

    eokTLJ=1/kToeLJ;

    FactorLJ=3*quadl(@(rLJ)((1-exp(-

    4.*eokTLJ.*((rLJ).^(-12)-(rLJ).^(-6)))).*rLJ.^2),0.01,15);

    integ1(iLJ)=FactorLJ;

    integLJ=integ1(iLJ);

    TLJ=kTeLJ.*eKLJ;

    BLJ(iLJ)=B1*integLJ;

    %Plot of Lennard Jones potential;

    plot(TLJ,BLJ,'*b');

    xlabel('{\it T},K');

    ylabel('{\it BLJ},cm3/mol');

    axis tight;

    For Kihara Potential

    %Data and constants;

    Na= 6.022e23; % particles/mol;

    as=0.470; % data from table 5-3 praust-

    nitz 1999;

    sK=4.611e-8; % cm;

    eKK=501.89; % K;

    %calculations from ppt 5 slide 78-80;

    B2=((2*pi)/3)*Na*(sK^3);

    kTeK=0.3:0.01:5;

    kToeK=kTeK(iK);

    eokTK=1/kToeK;

    a=as/(1+as);

    beg2a=a+0.0001;

    FactorK=quadl(@(rK)((1-exp(-4.*eokTK.*

    (((1-a)./(rK-a)).^(12)-((1-a)./(rK-a)).^6))).*rK.^2),beg2a,15);

    integ2(iK)=3.*(a.^3+FactorK);

    integK=integ2(iK);

    TK=kTeK*eKK;

    BK(iK)=B2*integK;

    %Plot of Kihara potential;

    plot(TK,BK,'*r');

    xlabel('{\it T},K');ylabel('{\it BLJ},cm3/mol');

    axis tight;

    Instructions: Calculate the second virial coefficient B2 for temperatures kT/ = 0.3 to 5.0 for C3H8

    from (a) Lennard-Jones Potential, (b) Kihara Potantial, (cO Pitzer-Tssonopoulos correlation. Plot B2

    (cm3/mol) vs Temperature (K) for three different methods in a single figure

  • 8/4/2019 Compiled Learning Tasks

    9/17

    For Pitzer-Tsonopoulos correlation

    %Data and Constants;

    Tc=369.8; % K;

    Pc=42.5; % bar;

    w=0.153; % accentric factor;

    Gc=83.1451; % bar cm3/mol K;

    TPT=0:10:2500;

    tkt=TPT(iPT);

    Tr=tkt./Tc;

    Fo=0.1445-(0.33./Tr)-(0.1385./(Tr.^2))-

    (0.0121./(Tr.^3))-(0.000607./(Tr.^8));

    F1=0.0637+(0.331./(Tr.^2))-(0.423./

    (Tr.^3))-(0.008./(Tr.^8));

    factorPT=Fo+(w*F1);

    integ3(iPT)=factorPT;

    BPRT=integ3(iPT);

    BPT(iPT)=BPRT*((Gc*Tc)/Pc);

    %Plot of Pitzer-Tsonopoulos Correlation;

    plot(TPT,BPT,'*g');

    xlabel('{\it T},K');

    ylabel('{\it BLJ},cm3/mol');

    axis([0,2500,-7000,100]);

    For Combined plot

    %Plot of the three methods

    plot

    (TLJ,BLJ,'*b',TK,BK,'*r',TPT,BPT,'*g')

    xlabel('{\it T}, K');

    ylabel('{\it B2}, cm^3/mol');

    legend('Lennard-Jones potential','Kihara

    potential','Pitzer-Tsonopoulos poten',4)

    axis([0,2550,-7000,1000]);

  • 8/4/2019 Compiled Learning Tasks

    10/17

    File Viewer

  • 8/4/2019 Compiled Learning Tasks

    11/17

  • 8/4/2019 Compiled Learning Tasks

    12/17

  • 8/4/2019 Compiled Learning Tasks

    13/17

  • 8/4/2019 Compiled Learning Tasks

    14/17

  • 8/4/2019 Compiled Learning Tasks

    15/17

    Quiz 2

    %problem 1a;

    %Data and Constants;

    Ta=449.5455; %K;

    Pa=7.0909; %bar;

    Na=6.022e23; %particles/mol;

    Gc=83.1451e-6; %gas constant in bar m3/

    mol K;

    ya=[0.22 0.78]; %mole fraction compo-

    nents;

    s=[5.22e-10 5.711e-10]; %in m;

    ek=[194.14 233.28]; %in K;

    Bo=2*pi*Na;

    b2i=[0 0];

    for i=1:2;

    ekT=ek(i)/Ta;

    factora=quadl(@(ra)((1-exp(-4.*ekT.*

    ((ra).^(-12)-(ra).^(-

    6)))).*ra.^2),0.01,15);

    BLJi(i)=Bo*s(i)^3*factora;

    factora=quadl(@(ra)((1-exp(-4.*ekT.*

    ((ra).^(-12)-(ra).^(-

    6)))).*ra.^2),0.01,15);

    BLJi(i)=Bo*s(i)^3*factora;

    end

    %output answers;

    disp(['Answers']);

    disp(['B of C2H6: ',num2str(BLJi(1)),'

    m3/mol']);

    disp(['B of C3H8: ',num2str(BLJi(2)),'

    m3/mol']);

    %problem 1b;

    %legend;

    %C2H6(1)-C2H6(1)=j(1);

    %C2H6(1)-C3H8(2)=j(2);

    %C3H8(2)-C3H8(2)=j(3);

    %Data and Constants;

    Tb=449.5455; %K;

    Pb=7.0909; %bar;

    Na=6.022e23; %particles/mol;

    Gc=83.1451e-6; %gas constant in bar m3/

    mol K;

    yb=[0.22 0.78]; %mole fraction compo-

    nents;

    s=[5.22e-10 5.711e-10]; %in m;

    ek=[194.14 233.28]; %in K;

    Bo=2*pi*Na;

    sb=[0 0 0];

    sb(1)=0.5*(s(1)+s(1));

    sb(2)=0.5*(s(1)+s(2));

    sb(3)=0.5*(s(2)+s(2));

    ekb=[0 0 0];

    ekb(1)=(ek(1)*ek(1))^0.5;ekb(2)=(ek(1)*ek(2))^0.5;

    ekb(3)=(ek(2)*ek(2))^0.5;

    Bm=[0 0 0];

    sb;

    ekb;

    for j=1:3

    ekTm=ekb(j)/Tb;

    factorb=quadl(@(rb)((1-exp(-4.*ekTm.*

    ((rb).^(-12)-(rb).^(-

    6)))).*rb.^2),0.01,15);

    Bm(j)=Bo*sb(j)^3*factorb;

    ekTm=ekb(j)/Tb;

    factorb=quadl(@(rb)((1-exp(-4.*ekTm.*

    ((rb).^(-12)-(rb).^(-

    6)))).*rb.^2),0.01,15);

    Bm(j)=Bo*sb(j)^3*factorb;

    ekTm=ekb(j)/Tb;

    factorb=quadl(@(rb)((1-exp(-4.*ekTm.*

    ((rb).^(-12)-(rb).^(-

    6)))).*rb.^2),0.01,15);Bm(j)=Bo*sb(j)^3*factorb;

    end

    Bm;

    %Bmix calculations;

    Bmix1=(yb(1)^2)*Bm(1);

    Bmix2=2*yb(1)*yb(2)*Bm(2);

    Bmix3=(yb(2)^2)*Bm(3);

  • 8/4/2019 Compiled Learning Tasks

    16/17

    Bmix=Bmix1+Bmix2+Bmix3;

    %output answers;

    disp(['Answers']);

    disp(['B(mixt) of C2H6-C2H6: ',num2str(Bm

    (1)),' m3/mol']);

    disp(['B(mixt) of C2H6-C3H8: ',num2str(Bm

    (2)),' m3/mol']);

    disp(['B(mixt) of C3H8-C3H8: ',num2str(Bm

    (3)),' m3/mol']);

    disp(['B(mix) = ',num2str(Bmix),' m3/

    mol']);

    %Problem 1c;

    %using previous data and parameters;

    Tc=449.5455; %K;

    Pc=7.0909; %bar;

    Na=6.022e23; %particles/mol;

    Gc=83.1451e-6; %gas constant in bar m3/

    mol K;

    yc=[0.22 0.78]; %mole fraction compo-

    nents;

    %calculations;

    lnfc1=(Pc/(Gc*Tc))*(2*((yc(1)*Bm(1))+(yc

    (1)*Bm(2)))-Bmix);

    lnfc2=(Pc/(Gc*Tc))*(2*((yc(2)*Bm(2))+(yc

    (2)*Bm(3)))-Bmix);

    fc1=exp(lnfc1);

    fc2=exp(lnfc2);

    %output answers;

    disp(['Answers']);

    disp(['Fugacity Coefficient of C2H6:

    ',num2str(fc1),' ']);

    disp(['Fugacity Coefficient of C3H8:

    ',num2str(fc2),' ']);

    % problem 2;

    %input data;

    %data [T(K) B(m3/gmol)];

    data=[330 -9.7707

    370 -7.3893

    410 -5.6488

    450 -4.3256

    490 -3.2880

    530 -2.4538

    570 -1.7695

    610 -1.1984

    650 -0.71487

    690 -0.30045

    730 0.058557];

    Gc=83.1451e-6;

    Bact=data(:,2);

    Tact=data(:,1);

    unk0=[374 0.1 16]; %[Tc w Pc] in order,

    initial guess;

    [unkhat resid J]=nlinfit

    (Tact,Bact,pct,unk0);

    unkhat;

    Bcal=pct(unkhat,Tact);

    disp(['Critical Parameters']);

    disp([' Critical Temperature: ',num2str

    (unkhat(1),' K']);

    disp([' Critical Pressure: ',num2str

    (unkhat(3),' bar ']);

    disp([' Accentric Factor: ',num2str

    (unkhat(2),' ']);

    PCT M-file

    function [ Bhat ] = pct(unk,Tact)%PCT Summary of this function goes here% Detailed explanation goes here

    Gc=83.1451e-6;

    F0=0.1445-(0.330./(Tact./unk(1)))-

    (0.1385./(Tact./unk(1)).^2)-(0.0121./

    (Tact./unk(1))^3)-(0.000607./(Tact./unk

    (1)).^8);F1=0.0637+(0.331./(Tact./unk(1)).^2)-

    (0.423./(Tact./unk(1)).^3)-(0.008./

    (Tact./unk(1)).^8);Bfunct=F0+unk(2).*F1;Bhat=(Gc*unk(1).*Bfunct)./unk(3);end

  • 8/4/2019 Compiled Learning Tasks

    17/17