Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Pleasesee me code first and use Matlab. Thank You! Balance Chemical Equations 1 Write a function BalanceChemical to balance chemical reactions by solving a linear
Pleasesee me code first and use Matlab. Thank You!
Balance Chemical Equations 1 Write a function BalanceChemical to balance chemical reactions by solving a linear set of equations. The inputs arguments are: 1. Reagents: Symbols of reagents in string row array 2. Products: Symbols of products in string row array 3. Elements: Elements in the reaction in string row array 4. ElCmpReag: Elemental composition of reactants in two dimensional numeric array 5. ElCmpPrdcts: Elemental composition of prducts in two dimensional numeric array Hint: The first part of the problem is setting up the set of linear equations that should be solve. The second part of the problem is to find the integers from the solution. One way to do this is to mulitiply the rational basis for the nullspace by increasing larger integers until both the left- and right-side integers exist. For example, for the reaction that involves CHs reacting with 02 to produce CO2 and H20: Reagents-["CH4", "O2"]; ElCmpReag-[1,4,0; Products =["c02", "H20"]; Elements -("C","H", "O..] 0,0,21; where the first row corresponds to elements in Reagents (1), 2nd to Reagents(2), etc. given in the order specified by Elements ElCmpPrdcts [1,0,2; where the first row corresponds to Products (1), 2nd to Products (2), etc. given in the order specified by Elements. The outputs arguments are: 1. leftsidelntegers: Left-side integers of reactants to balance the equation 2. rightsidelnteger: Right-side integers products to balance the equation 3. coefMat: The coefficient matrix that was composed to balance the equation For example, balance CH, + O2-, CO2 + H2O >>Reagents- ["CH4", "02"]; Products["CO2", "H20"]; >>Elements ["C", "H","0"] ;ElCmpReag [1,4,0;0,0,2]; ElCmpPrdcts [1,0,2;0,2,1]; >>[leftsideIntegers, rightsideIntegers, coefMat] = BalanceChemical(Reagents,Products,Elements,ELCmpReag,ELCml leftsideIntegers 1x2 uint8row vector rightsideIntegers 1x2 uint8row vector 4 Balance HIO3 +Fe2 + HClFeCl ICl+H20 >>Reagents-["HI03", "FeI2","HC1" Products ["FeC13", "IC", "H20": >>Elements["H", "I", "O", "Fe", "cl"]; >>ELCmpReag- [1, 1, 3, 0, 2, 1, 0, 0, 1 >ElCmpPrdcts-[ O, 0, 0, [leftsideIntegers, leftsideIntegers- rightsideIntegers] BalanceChemical(Reagents,Products,Elements,ELCmpReag,ELCmpPrdcts) = 1x3 uint8row vector 4 25 5 rightsideIntegers 1x3 uint8row vector 4 13 15 1 function [leftsideIntegers, rightsideIntegers, coefMat] BalanceChemical (Reagents, Products,Elements,EL 2coefMat [ElCmpReag'-ELCmpReag' 3 [red_num,-size(ElCmpReag); 4 ech_form rref(coefMat): 5 vect ech_form(:,4); 6 free_var-1 7while(1) if(all(floor(vect )-zyect)) break; 10 else free_var-free_var+1; vect-free_varkvect; 12 13 4end 5 vect abs(vect) free_varl: 16 eftsideIntegers vect (1:red_num); 17 rightsideIntegers-vect (red_num+1: length (vect)): 18 19 20 end end % Your code goes here Code to call your function C Reset 1 eagents-["CH4", "02"]; Products ["CO2", "H20"]: 2Lements :["C","H","O.. ] ;ELCmpReage [ 1,4,0; 0,0,2]; ELCmpPrdct sa(1,0,2;0,2,1]; 3 leftsidelntegers, rightsideIntegers, coefMat] = BalanceChemical(Reagents,Products,Elements,E1CmpReag , ELC 4 Assessment: 0 of 3 Tests Passed Submit 2 Coefficient Matrix: React Cu and HNO3 to produce Cu(NO3)2, NO and H20 Variable ycoefMat must be of size [4 5]. It is currently of size [4 4]. Check where the variable is assigned a value. The coefficient matrix is incorrect Left Integers: React Cu and HNO3 to produce Cu(NO3)2, NO and H20 Variable y must be of data type uint8. It is currently of type double. Check where the variable is assigned a value. Left integers are incorrect Right Integers: React Cu and HNO3 to produce Cu(NO3)2, NO and H20 Variable y must be of data type uint8. It is currently of type double. Check where the variable is assigned a value. Right integers are incorrect Balance Chemical Equations 1 Write a function BalanceChemical to balance chemical reactions by solving a linear set of equations. The inputs arguments are: 1. Reagents: Symbols of reagents in string row array 2. Products: Symbols of products in string row array 3. Elements: Elements in the reaction in string row array 4. ElCmpReag: Elemental composition of reactants in two dimensional numeric array 5. ElCmpPrdcts: Elemental composition of prducts in two dimensional numeric array Hint: The first part of the problem is setting up the set of linear equations that should be solve. The second part of the problem is to find the integers from the solution. One way to do this is to mulitiply the rational basis for the nullspace by increasing larger integers until both the left- and right-side integers exist. For example, for the reaction that involves CHs reacting with 02 to produce CO2 and H20: Reagents-["CH4", "O2"]; ElCmpReag-[1,4,0; Products =["c02", "H20"]; Elements -("C","H", "O..] 0,0,21; where the first row corresponds to elements in Reagents (1), 2nd to Reagents(2), etc. given in the order specified by Elements ElCmpPrdcts [1,0,2; where the first row corresponds to Products (1), 2nd to Products (2), etc. given in the order specified by Elements. The outputs arguments are: 1. leftsidelntegers: Left-side integers of reactants to balance the equation 2. rightsidelnteger: Right-side integers products to balance the equation 3. coefMat: The coefficient matrix that was composed to balance the equation For example, balance CH, + O2-, CO2 + H2O >>Reagents- ["CH4", "02"]; Products["CO2", "H20"]; >>Elements ["C", "H","0"] ;ElCmpReag [1,4,0;0,0,2]; ElCmpPrdcts [1,0,2;0,2,1]; >>[leftsideIntegers, rightsideIntegers, coefMat] = BalanceChemical(Reagents,Products,Elements,ELCmpReag,ELCml leftsideIntegers 1x2 uint8row vector rightsideIntegers 1x2 uint8row vector 4 Balance HIO3 +Fe2 + HClFeCl ICl+H20 >>Reagents-["HI03", "FeI2","HC1" Products ["FeC13", "IC", "H20": >>Elements["H", "I", "O", "Fe", "cl"]; >>ELCmpReag- [1, 1, 3, 0, 2, 1, 0, 0, 1 >ElCmpPrdcts-[ O, 0, 0, [leftsideIntegers, leftsideIntegers- rightsideIntegers] BalanceChemical(Reagents,Products,Elements,ELCmpReag,ELCmpPrdcts) = 1x3 uint8row vector 4 25 5 rightsideIntegers 1x3 uint8row vector 4 13 15 1 function [leftsideIntegers, rightsideIntegers, coefMat] BalanceChemical (Reagents, Products,Elements,EL 2coefMat [ElCmpReag'-ELCmpReag' 3 [red_num,-size(ElCmpReag); 4 ech_form rref(coefMat): 5 vect ech_form(:,4); 6 free_var-1 7while(1) if(all(floor(vect )-zyect)) break; 10 else free_var-free_var+1; vect-free_varkvect; 12 13 4end 5 vect abs(vect) free_varl: 16 eftsideIntegers vect (1:red_num); 17 rightsideIntegers-vect (red_num+1: length (vect)): 18 19 20 end end % Your code goes here Code to call your function C Reset 1 eagents-["CH4", "02"]; Products ["CO2", "H20"]: 2Lements :["C","H","O.. ] ;ELCmpReage [ 1,4,0; 0,0,2]; ELCmpPrdct sa(1,0,2;0,2,1]; 3 leftsidelntegers, rightsideIntegers, coefMat] = BalanceChemical(Reagents,Products,Elements,E1CmpReag , ELC 4 Assessment: 0 of 3 Tests Passed Submit 2 Coefficient Matrix: React Cu and HNO3 to produce Cu(NO3)2, NO and H20 Variable ycoefMat must be of size [4 5]. It is currently of size [4 4]. Check where the variable is assigned a value. The coefficient matrix is incorrect Left Integers: React Cu and HNO3 to produce Cu(NO3)2, NO and H20 Variable y must be of data type uint8. It is currently of type double. Check where the variable is assigned a value. Left integers are incorrect Right Integers: React Cu and HNO3 to produce Cu(NO3)2, NO and H20 Variable y must be of data type uint8. It is currently of type double. Check where the variable is assigned a value. Right integers are incorrectStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started