Homework Solution: Complete The Matlab function "phaseFinder" which takes two inputs, a temperature and…

    Complete The Matlab function "phaseFinder" which takes two inputs, a temperature and composisiton of a two part mixture and returns its corresponding location on the provided phase diagram. The input temperature is to be non-negative and measured in Celcius. The input composition of the mixture is to be the percentage of Component B, within the two part (A + B) mixture. (e.g For a mixture of 25% material A and 75% material B, CompB = 75) ******DO NOT EDIT THE "phaseFinder" FUNCTION****** Your task is to complete two of the functions used within "phaseFinder". Those Functions are: "checkBetaLiquid(T,B)" "checkBeta(T,B)" Code: function result = phaseFinder(Temp, CompB) %checks the inputs are valid validInputs = testInputConditions(Temp, CompB); if validInputs == 1 %Determine which regions the inputs correspond to. a = checkAlpha(Temp, CompB); b = checkBeta(Temp, CompB); l = checkLiquid(Temp, CompB); a_b = checkAlphaBeta(Temp,CompB); a_l = checkAlphaLiquid(Temp,CompB); b_l = checkBetaLiquid(Temp,CompB); %Creates an array indicating correspondance of inputs to regions testArray = [a b l a_b a_l b_l]; %Check if the mixture sits at the Eutectic Point if isequal(testArray, [0 0 1 1 1 1]) fprintf('Mixture sits on the Eutectic Point r'); result = 1; %Check if the mixture sits at the juntion of any three regions elseif isequal(testArray, [1 0 0 1 1 0]) fprintf(['Mixture sits on the alpha/alpha_liquid/alpha_beta ' ... 'junction on the Eutectic Line r']); result = 2; elseif isequal(testArray, [0 1 0 1 0 1]) fprintf(['Mixture sits on the beta/beta_liquid/alpha_beta ' ... 'junction on the Eutectic Line r']); result = 3; elseif isequal(testArray, [1 0 1 0 1 0]) fprintf(['Mixture sits on the alpha/alpha_liquid/liquid' ... 'junction r']); result = 4; elseif isequal(testArray, [0 1 1 0 0 1]) fprintf(['Mixture sits on the beta/beta_liquid/liquid' ... 'junction r']); result = 5; %Check if the mixture sits at the border of any two regions elseif isequal(testArray, [1 0 0 1 0 0]) fprintf('Mixture sits on the alpha/alpha_beta border r'); result = 6; elseif isequal(testArray, [1 0 0 0 1 0]) fprintf('Mixture sits on the alpha/alpha_liquid border r'); result = 7; elseif isequal(testArray, [0 0 0 1 1 0]) fprintf(['Mixture sits on the alpha_liquid/alpha_beta ' ... 'border on the Eutectic Line r']); result = 8; elseif isequal(testArray, [0 1 0 1 0 0]) fprintf('Mixture sits on the beta/alpha_beta border r'); result = 9; elseif isequal(testArray, [0 0 0 1 0 1]) fprintf(['Mixture sits on the beta_liquid/alpha_beta ' ... 'border on the Eutectic Line r']); result = 10; elseif isequal(testArray, [0 1 0 0 0 1]) fprintf('Mixture sits on the beta/beta_liquid border r'); result = 11; elseif isequal(testArray, [0 0 1 0 1 0]) fprintf('Mixture sits on the liquid/alpha_liquid border r'); result = 12; elseif isequal(testArray, [0 0 1 0 0 1]) fprintf('Mixture sits on the liquid/beta_liquid border r'); result = 13; %check if the mixture sits at within only one of the regions elseif isequal(testArray, [1 0 0 0 0 0]) fprintf('Mixture belongs to the alpha region r'); result = 14; elseif isequal(testArray, [0 1 0 0 0 0]) fprintf('Mixture belongs to the beta region r'); result = 15; elseif isequal(testArray, [0 0 1 0 0 0]) fprintf('Mixture belongs to the liquid region r'); result = 16; elseif isequal(testArray, [0 0 0 1 0 0]) fprintf('Mixture belongs to the alpha_beta region r'); result = 17; elseif isequal(testArray, [0 0 0 0 1 0]) fprintf('Mixture belongs to the alpha_liquid region r'); result = 18; elseif isequal(testArray, [0 0 0 0 0 1]) fprintf('Mixture belongs to the beta_liquid region r'); result = 19; %Declares that the mixture is not within any of the defined regions else fprintf(['Mixture belongs to an immpossible combination of' ... ' regions r ... that can''t be right r']); result = 20; end else %Inputs were not valid result = -1; end end %The Following function checks that; %Input Temperature is non-negative %Input Composition is between 0 and 100 %DO NOT EDIT THIS FUNCTION function test = testInputConditions(T,B) if (T >= 0) && (B >= 0) && (B <= 100) test = 1; else test = 0; if (T < 0) fprintf('Input Error: Temp(Celcius) must be +ve integer r'); end if (B < 0) || (B >100) fprintf('Input Error: Comp(%%A) must be between 0 and 100 r'); end end end %The Following function checks if input conditions indicate that the %mixture is in the 'alpha' region. %DO NOT EDIT THIS FUNCTION function a = checkAlpha(T,B) maxTemp = -(400/15)*B + 700; minTemp = 20*B; if (T <= maxTemp) && (T >= minTemp) a = 1; else a = 0; end end %The Following function checks if input conditions indicate that the %mixture is in the 'alpha + beta' region. %DO NOT EDIT THIS FUNCTION function a_b = checkAlphaBeta(T,B) minComp = 0.05*T; maxComp = 100 - 0.05*T; if (T <= 300) && (B >= minComp) && (B <= maxComp) a_b = 1; else a_b = 0; end end %The Following function checks if input conditions indicate that the %mixture is in the 'alpha + liquid' region. %Sets output to 1 if the mixtue is WITHIN the region, otherwise sets to 0. %DO NOT EDIT THIS FUNCTION function a_liquid = checkAlphaLiquid(T,B) minComp = 26.25 - 0.0375*T; maxComp = 87.5 - (T/8); if (T>= 300) && (T <= 700) && (B >= minComp) && (B <= maxComp) a_liquid = 1; else a_liquid = 0; end end %The Following function checks if input conditions indicate that the %mixture is in the 'beta + liquid' region. %Sets output to 1 if the mixtue is WITHIN the region, otherwise sets to 0. function b_liquid = checkBetaLiquid(T,B) b_liquid = 1;%REMOVE THIS LINE AND COMPLETE THE FUNCTION end %The Following function checks if input conditions indicate that the %mixture is in the 'liquid' region. %Sets output to 1 if the mixtue is WITHIN the region, otherwise sets to 0. %DO NOT EDIT THIS FUNCTION function liquid = checkLiquid(T,B) minAlphaTemp = 700 - 8*B; minBetaTemp = 10*B - 200; if (T >= minAlphaTemp) && (T >= minBetaTemp) liquid = 1; else liquid = 0; end end %The Following function checks if input conditions indicate that the %mixture is in the 'beta' region. %Sets output to 1 if the mixtue is WITHIN the region, otherwise sets to 0. function b = checkBeta(T,B) b = 0;%REMOVE THIS LINE AND COMPLETE THE FUNCTION end

    Expert Answer

     
    function result = phaseFinder(Temp, CompB) %checks the inputs are valid

    Total The Matlab duty “phaseFinder” which takes couple inputs, a temperature and
    composisiton of a couple disunite adjustment and produce its selfsame location
    on the supposing deportment diagram.

    The input temperature is to be non-negative and measured in Celcius. The
    input compound of the adjustment is to be the percentage of Component B,
    amid the couple disunite (A + B) adjustment.
    (e.g For a adjustment of 25% symbolical A and 75% symbolical B, CompB = 75)

    ******DO NOT EDIT THE “phaseFinder” FUNCTION******

    Your business is to total couple of the dutys used amid “phaseFinder”.
    Those Dutys are:
    “checkBetaLiquid(T,B)”
    “checkBeta(T,B)”

    Code:

    duty conclusion = deportmentFinder(Temp, CompB)
    %checks the inputs are valid
    validInputs = experimentInputConditions(Temp, CompB);

    if validInputs == 1
    %Determine which districts the inputs fit to.
    a = checkAlpha(Temp, CompB);
    b = checkBeta(Temp, CompB);
    l = checkLiquid(Temp, CompB);
    a_b = checkAlphaBeta(Temp,CompB);
    a_l = checkAlphaLiquid(Temp,CompB);
    b_l = checkBetaLiquid(Temp,CompB);

    %Creates an set-in-order indicating fitance of inputs to districts
    testSet-in-order = [a b l a_b a_l b_l];

    %Check if the adjustment sits at the Eutectic Point
    if isequal(testArray, [0 0 1 1 1 1])
    fprintf(‘Adjustment sits on the Eutectic Point r’);
    conclusion = 1;

    %Check if the adjustment sits at the juntion of any three districts
    elseif isequal(testArray, [1 0 0 1 1 0])
    fprintf([‘Adjustment sits on the alpha/alpha_liquid/alpha_beta ‘ …
    ‘junction on the Eutectic Line r’]);
    conclusion = 2;
    elseif isequal(testArray, [0 1 0 1 0 1])
    fprintf([‘Adjustment sits on the beta/beta_liquid/alpha_beta ‘ …
    ‘junction on the Eutectic Line r’]);
    conclusion = 3;
    elseif isequal(testArray, [1 0 1 0 1 0])
    fprintf([‘Adjustment sits on the alpha/alpha_liquid/liquid’ …
    ‘junction r’]);
    conclusion = 4;
    elseif isequal(testArray, [0 1 1 0 0 1])
    fprintf([‘Adjustment sits on the beta/beta_liquid/liquid’ …
    ‘junction r’]);
    conclusion = 5;

    %Check if the adjustment sits at the edging of any couple districts
    elseif isequal(testArray, [1 0 0 1 0 0])
    fprintf(‘Adjustment sits on the alpha/alpha_beta edging r’);
    conclusion = 6;
    elseif isequal(testArray, [1 0 0 0 1 0])
    fprintf(‘Adjustment sits on the alpha/alpha_watery edging r’);
    conclusion = 7;
    elseif isequal(testArray, [0 0 0 1 1 0])
    fprintf([‘Adjustment sits on the alpha_liquid/alpha_beta ‘ …
    ‘edging on the Eutectic Line r’]);
    conclusion = 8;
    elseif isequal(testArray, [0 1 0 1 0 0])
    fprintf(‘Adjustment sits on the beta/alpha_beta edging r’);
    conclusion = 9;
    elseif isequal(testArray, [0 0 0 1 0 1])
    fprintf([‘Adjustment sits on the beta_liquid/alpha_beta ‘ …
    ‘edging on the Eutectic Line r’]);
    conclusion = 10;

    elseif isequal(testArray, [0 1 0 0 0 1])
    fprintf(‘Adjustment sits on the beta/beta_watery edging r’);
    conclusion = 11;
    elseif isequal(testArray, [0 0 1 0 1 0])
    fprintf(‘Adjustment sits on the watery/alpha_watery edging r’);
    conclusion = 12;
    elseif isequal(testArray, [0 0 1 0 0 1])
    fprintf(‘Adjustment sits on the watery/beta_watery edging r’);
    conclusion = 13;

    %check if the adjustment sits at amid barely individual of the districts
    elseif isequal(testArray, [1 0 0 0 0 0])
    fprintf(‘Adjustment belongs to the alpha district r’);
    conclusion = 14;
    elseif isequal(testArray, [0 1 0 0 0 0])
    fprintf(‘Adjustment belongs to the beta district r’);
    conclusion = 15;
    elseif isequal(testArray, [0 0 1 0 0 0])
    fprintf(‘Adjustment belongs to the watery district r’);
    conclusion = 16;
    elseif isequal(testArray, [0 0 0 1 0 0])
    fprintf(‘Adjustment belongs to the alpha_beta district r’);
    conclusion = 17;
    elseif isequal(testArray, [0 0 0 0 1 0])
    fprintf(‘Adjustment belongs to the alpha_watery district r’);
    conclusion = 18;
    elseif isequal(testArray, [0 0 0 0 0 1])
    fprintf(‘Adjustment belongs to the beta_watery district r’);
    conclusion = 19;

    %Declares that the adjustment is referable attributable attributable attributable attributable attributable attributable amid any of the defined districts
    else
    fprintf([‘Adjustment belongs to an immpossible coalition of’ …
    ‘ districts r … that can”t be fair r’]);
    conclusion = 20;
    end
    else
    %Inputs were referable attributable attributable attributable attributable attributable attributable valid
    conclusion = -1;
    end
    end

    %The Following duty checks that;
    %Input Temperature is non-negative
    %Input Compound is among 0 and 100
    %DO NOT EDIT THIS FUNCTION
    duty experiment = experimentInputConditions(T,B)
    if (T >= 0) && (B >= 0) && (B <= 100)
    experiment = 1;
    else
    experiment = 0;
    if (T < 0)
    fprintf(‘Input Error: Temp(Celcius) must be +ve integer r’);
    end
    if (B < 0) || (B >100)
    fprintf(‘Input Error: Comp(%%A) must be among 0 and 100 r’);
    end
    end
    end

    %The Following duty checks if input provisions betray that the
    %adjustment is in the ‘alpha’ district.
    %DO NOT EDIT THIS FUNCTION

    duty a = checkAlpha(T,B)
    maxTemp = -(400/15)*B + 700;
    minTemp = 20*B;
    if (T <= maxTemp) && (T >= minTemp)
    a = 1;
    else
    a = 0;
    end
    end

    %The Following duty checks if input provisions betray that the
    %adjustment is in the ‘alpha + beta’ district.
    %DO NOT EDIT THIS FUNCTION

    duty a_b = checkAlphaBeta(T,B)
    minComp = 0.05*T;
    maxComp = 100 – 0.05*T;
    if (T <= 300) && (B >= minComp) && (B <= maxComp)
    a_b = 1;
    else
    a_b = 0;
    end
    end

    %The Following duty checks if input provisions betray that the
    %adjustment is in the ‘alpha + watery’ district.
    %Sets output to 1 if the mixtue is WITHIN the district, incorrectly sets to 0.
    %DO NOT EDIT THIS FUNCTION
    duty a_watery = checkAlphaLiquid(T,B)
    minComp = 26.25 – 0.0375*T;
    maxComp = 87.5 – (T/8);
    if (T>= 300) && (T <= 700) && (B >= minComp) && (B <= maxComp)
    a_watery = 1;
    else
    a_watery = 0;
    end
    end

    %The Following duty checks if input provisions betray that the
    %adjustment is in the ‘beta + watery’ district.
    %Sets output to 1 if the mixtue is WITHIN the district, incorrectly sets to 0.

    duty b_watery = checkBetaLiquid(T,B)
    b_watery = 1;%REMOVE THIS LINE AND COMPLETE THE FUNCTION
    end

    %The Following duty checks if input provisions betray that the
    %adjustment is in the ‘liquid’ district.
    %Sets output to 1 if the mixtue is WITHIN the district, incorrectly sets to 0.
    %DO NOT EDIT THIS FUNCTION

    duty watery = checkLiquid(T,B)
    minAlphaTemp = 700 – 8*B;
    minBetaTemp = 10*B – 200;
    if (T >= minAlphaTemp) && (T >= minBetaTemp)
    watery = 1;
    else
    watery = 0;
    end
    end

    %The Following duty checks if input provisions betray that the
    %adjustment is in the ‘beta’ district.
    %Sets output to 1 if the mixtue is WITHIN the district, incorrectly sets to 0.

    duty b = checkBeta(T,B)
    b = 0;%REMOVE THIS LINE AND COMPLETE THE FUNCTION
    end

    Expert Reply

     

    duty conclusion = deportmentFinder(Temp, CompB)
    %checks the inputs are valid
    validInputs = experimentInputConditions(Temp, CompB);

    if validInputs == 1
    %Determine which districts the inputs fit to.
    a = checkAlpha(Temp, CompB);
    b = checkBeta(Temp, CompB);
    l = checkLiquid(Temp, CompB);
    a_b = checkAlphaBeta(Temp,CompB);
    a_l = checkAlphaLiquid(Temp,CompB);
    b_l = checkBetaLiquid(Temp,CompB);

    %Creates an set-in-order indicating fit.ance of inputs to districts
    testSet-in-order = [a b l a_b a_l b_l];

    %Check if the adjustment sits at the Eutectic Point
    if isequal(testArray, [0 0 1 1 1 1])
    fprintf(‘Adjustment sits on the Eutectic Point r’);
    conclusion = 1;

    %Check if the adjustment sits at the juntion of any three districts
    elseif isequal(testArray, [1 0 0 1 1 0])
    fprintf([‘Adjustment sits on the alpha/alpha_liquid/alpha_beta ‘ …
    ‘junction on the Eutectic Line r’]);
    conclusion = 2;
    elseif isequal(testArray, [0 1 0 1 0 1])
    fprintf([‘Adjustment sits on the beta/beta_liquid/alpha_beta ‘ …
    ‘junction on the Eutectic Line r’]);
    conclusion = 3;
    elseif isequal(testArray, [1 0 1 0 1 0])
    fprintf([‘Adjustment sits on the alpha/alpha_liquid/liquid’ …
    ‘junction r’]);
    conclusion = 4;
    elseif isequal(testArray, [0 1 1 0 0 1])
    fprintf([‘Adjustment sits on the beta/beta_liquid/liquid’ …
    ‘junction r’]);
    conclusion = 5;

    %Check if the adjustment sits at the edging of any couple districts
    elseif isequal(testArray, [1 0 0 1 0 0])
    fprintf(‘Adjustment sits on the alpha/alpha_beta edging r’);
    conclusion = 6;
    elseif isequal(testArray, [1 0 0 0 1 0])
    fprintf(‘Adjustment sits on the alpha/alpha_watery edging r’);
    conclusion = 7;
    elseif isequal(testArray, [0 0 0 1 1 0])
    fprintf([‘Adjustment sits on the alpha_liquid/alpha_beta ‘ …
    ‘edging on the Eutectic Line r’]);
    conclusion = 8;
    elseif isequal(testArray, [0 1 0 1 0 0])
    fprintf(‘Adjustment sits on the beta/alpha_beta edging r’);
    conclusion = 9;
    elseif isequal(testArray, [0 0 0 1 0 1])
    fprintf([‘Adjustment sits on the beta_liquid/alpha_beta ‘ …
    ‘edging on the Eutectic Line r’]);
    conclusion = 10;

    elseif isequal(testArray, [0 1 0 0 0 1])
    fprintf(‘Adjustment sits on the beta/beta_watery edging r’);
    conclusion = 11;
    elseif isequal(testArray, [0 0 1 0 1 0])
    fprintf(‘Adjustment sits on the watery/alpha_watery edging r’);
    conclusion = 12;
    elseif isequal(testArray, [0 0 1 0 0 1])
    fprintf(‘Adjustment sits on the watery/beta_watery edging r’);
    conclusion = 13;

    %check if the adjustment sits at amid barely individual of the districts
    elseif isequal(testArray, [1 0 0 0 0 0])
    fprintf(‘Adjustment belongs to the alpha district r’);
    conclusion = 14;
    elseif isequal(testArray, [0 1 0 0 0 0])
    fprintf(‘Adjustment belongs to the beta district r’);
    conclusion = 15;
    elseif isequal(testArray, [0 0 1 0 0 0])
    fprintf(‘Adjustment belongs to the watery district r’);
    conclusion = 16;
    elseif isequal(testArray, [0 0 0 1 0 0])
    fprintf(‘Adjustment belongs to the alpha_beta district r’);
    conclusion = 17;
    elseif isequal(testArray, [0 0 0 0 1 0])
    fprintf(‘Adjustment belongs to the alpha_watery district r’);
    conclusion = 18;
    elseif isequal(testArray, [0 0 0 0 0 1])
    fprintf(‘Adjustment belongs to the beta_watery district r’);
    conclusion = 19;

    %Declares that the adjustment is referable attributable attributable attributable attributable attributable attributable amid any of the defined districts
    else
    fprintf([‘Adjustment belongs to an immpossible coalition of’ …
    ‘ districts r … that can”t be fair r’]);
    conclusion = 20;
    end
    else
    %Inputs were referable attributable attributable attributable attributable attributable attributable valid
    conclusion = -1;
    end
    end

    %The Following duty checks that;
    %Input Temperature is non-negative
    %Input Compound is among 0 and 100
    %DO NOT EDIT THIS FUNCTION
    duty experiment = experimentInputConditions(T,B)
    if (T >= 0) && (B >= 0) && (B <= 100)
    experiment = 1;
    else
    experiment = 0;
    if (T < 0)
    fprintf(‘Input Error: Temp(Celcius) must be +ve integer r’);
    end
    if (B < 0) || (B >100)
    fprintf(‘Input Error: Comp(%%A) must be among 0 and 100 r’);
    end
    end
    end

    %The Following duty checks if input provisions betray that the
    %adjustment is in the ‘alpha’ district.
    %DO NOT EDIT THIS FUNCTION

    duty a = checkAlpha(T,B)
    maxTemp = -(400/15)*B + 700;
    minTemp = 20*B;
    if (T <= maxTemp) && (T >= minTemp)
    a = 1;
    else
    a = 0;
    end
    end

    %The Following duty checks if input provisions betray that the
    %adjustment is in the ‘alpha + beta’ district.
    %DO NOT EDIT THIS FUNCTION

    duty a_b = checkAlphaBeta(T,B)
    minComp = 0.05*T;
    maxComp = 100 – 0.05*T;
    if (T <= 300) && (B >= minComp) && (B <= maxComp)
    a_b = 1;
    else
    a_b = 0;
    end
    end

    %The Following duty checks if input provisions betray that the
    %adjustment is in the ‘alpha + watery’ district.
    %Sets output to 1 if the mixtue is WITHIN the district, incorrectly sets to 0.
    %DO NOT EDIT THIS FUNCTION
    duty a_watery = checkAlphaLiquid(T,B)
    minComp = 26.25 – 0.0375*T;
    maxComp = 87.5 – (T/8);
    if (T>= 300) && (T <= 700) && (B >= minComp) && (B <= maxComp)
    a_watery = 1;
    else
    a_watery = 0;
    end
    end

    %The Following duty checks if input provisions betray that the
    %adjustment is in the ‘beta + watery’ district.
    %Sets output to 1 if the mixtue is WITHIN the district, incorrectly sets to 0.

    duty b_watery = checkBetaLiquid(T,B)
    if (T > 0)

    b_watery = 1;

    else

    b_watery = 0;
    end ;

    %The Following duty checks if input provisions betray that the
    %adjustment is in the ‘liquid’ district.
    %Sets output to 1 if the mixtue is WITHIN the district, incorrectly sets to 0.
    %DO NOT EDIT THIS FUNCTION

    duty watery = checkLiquid(T,B)
    minAlphaTemp = 700 – 8*B;
    minBetaTemp = 10*B – 200;
    if (T >= minAlphaTemp) && (T >= minBetaTemp)
    watery = 1;
    else
    watery = 0;
    end
    end

    %The Following duty checks if input provisions betray that the
    %adjustment is in the ‘beta’ district.
    %Sets output to 1 if the mixtue is WITHIN the district, incorrectly sets to 0.

    duty b = checkBeta(T,B)
    b = 0;%REMOVE THIS LINE AND COMPLETE THE FUNCTION
    end