# Thread: Need help with MATLAB question

1. ## Need help with MATLAB question

ok so the question is

The dissolution of copper sulfide in aqueous nitric acid is described by the following chemical equation

aCuS + bNO3^- + cH^+ = dCu^2+ + eSO4^2- + fNO + gH2O

where the coefficients a,b,c,d,e,f, and g are the numbers of each molecule participating in the reactiona nd 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=f, 3b=4e+f+g, c=2g, -b+c=2d-2e

There are seven unknowns and only six equations. A solution can still be obtained, however, by taking advantage of the fact that all the coefficients must be positive integers, Add a 7th equation by guessing a=1 and solve the system of equations. The solution is valid if all the coefficients are positive integers. If this is not the case take a=2 and repeat the solution. Continue the process until all the coefficients in the solution are positive integers.

I know how to solve the problem normally but do know how to do this in matlab. At first I tried to just type in all the equations into matlab and solve but that didn't work. Or am I supposed to set up a matrix? I don't know where to begin with this problem. Thanks

2. Originally Posted by truong123
ok so the question is

The dissolution of copper sulfide in aqueous nitric acid is described by the following chemical equation

aCuS + bNO3^- + cH^+ = dCu^2+ + eSO4^2- + fNO + gH2O

where the coefficients a,b,c,d,e,f, and g are the numbers of each molecule participating in the reactiona nd 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=f, 3b=4e+f+g, c=2g, -b+c=2d-2e

There are seven unknowns and only six equations. A solution can still be obtained, however, by taking advantage of the fact that all the coefficients must be positive integers, Add a 7th equation by guessing a=1 and solve the system of equations. The solution is valid if all the coefficients are positive integers. If this is not the case take a=2 and repeat the solution. Continue the process until all the coefficients in the solution are positive integers.

I know how to solve the problem normally but do know how to do this in matlab. At first I tried to just type in all the equations into matlab and solve but that didn't work. Or am I supposed to set up a matrix? I don't know where to begin with this problem. Thanks
Create a loop to loop over integer values for a and break out of the loop when the solution for the remaining variables meets your requirements.

To do the tests you will need a function to tell you if a double-prescission variable contains something to the limits of calculation can be considered an integer. Something like:

Code:
function rv=isintdd(x)
%
%  warning untested code follows
%
xx=round(x);
if abs((xx-x)/x)<1e-7
rv=1
else
rv=0
end
CB