Please help. I need help with the second question but in order to solve it you w
ID: 3593197 • Letter: P
Question
Please help. I need help with the second question but in order to solve it you will need to approach question 4 first. Would really appreciate if u can solve ques 4 and then the folllowing one. thanks
Please attach matlab code for both and command window as well thanks again
HW4P4 (15 points) The dissolution of copper sulfide in aqueous nitric acid is described by the following chemical equation where the coefficients a, b, c, d, e, f, and g are the numbers of the various molecules participating in the reaction and are unknown. The unknown coefficients are determined by balancing each atom on left and right and then balancing the ionic charge. The resulting equations are a=d a=e, b= 3b = 4e + f + g, c=2g, -b + c = 2d-2e , There are 7 unknowns and only 6 equations. A solution can still be obtained, however, by taking advantage of the fact that all the coefficients must be positive integers. Add a seventh equation by guessing the value of a and solve the system of equations. For example, your seventh equation can bea - K where K is a positive integer 1, 2,3 ...etc. The solution is valid only if all the coefficients (a, b, c, d, e,f, and g) are positive integers. If this is not the case, repeat the solution for a different value of the coefficient a. Rewrite your system of equations in matrix format Ax = b and then write a script file named HW4P4 that asks the user to input a value of K as a positive integer. The progranm then should solve the system of equations and compute the values of the coefficients a to g The program should display the output for in the format "When a-X·XX, b-X·XX c = X. XX, d-x.xx, e = X.XX , f = X.XX, and g = X.XX". Ifthe values of all coefficients are positive integers this means you have a solution. Otherwise, run the program again and enter another value for K until the coefficients are all positive integersExplanation / Answer
x=[2.8;0;0;0;0;0;0];
k=1;
while(floor(x(1,1))~= x(1,1) | floor(x(2,1))~= x(2,1) | floor(x(3,1))~= x(3,1) | floor(x(4,1))~= x(4,1) | floor(x(5,1))~= x(5,1) | floor(x(6,1))~= x(6,1) | floor(x(7,1))~= x(7,1) )
A = sparse([1,0,0,0,0,0,0;1,0,0,-1,0,0,0;1,0,0,0,-1,0,0;0,1,0,0,0,-1,0;0,-3,0,-1,4,1,1;1,0,0,0,0,0,-2;0,1,-1,1,-2,0,0]);
B = sparse([k;0;0;0;0;0;0]);
x = AB;
fprintf('Iter # %d ',k)
a = x(1,1)
b = x(2,1)
c = x(3,1)
d = x(4,1)
e = x(5,1)
f = x(6,1)
g = x(7,1)
k=k+1;
end