Displaying string with variables

1 visualización (últimos 30 días)
Rick
Rick el 9 de Nov. de 2015
Comentada: Walter Roberson el 9 de Nov. de 2015
Hello,
I'm trying to make a function that tell me the coefficients x,y, and z for a given n,a,b,c,d CnHaObNcSd + xH2O ---> yCH4 + zCO2 + cNH3 + dH2S
And return at output with a sentence
function ChemicalFormula = foodwastes(n,a,b,c,d)
x = n - a/4 - b/2 + 3/4*c + d/2;
y = n/2 + a/8 - b/4 - 3/8*c - d/4;
z = n/2 - a/8 + b/4 + 3/8*c + d/4;
display([' C ',num2str(n), 'H' ,num2str(a), ' O ' ,num2str(b), ' N ' ,num2str(c), ' S ' ,num2str(d),
' + ' ,num2str(x), ' H_{2}O \rightarrow ',num2str(y), ' CH_{4} + ' ,num2str(z), ' CO_{2} + ' ,num2str(c),
' NH_{3} + ' ,num2str(d), ' H_{2}S '])
MW = 16*n + 1*a + 16*b + 14*c + 32*d;
diplay(['Food Waste Molecular weight is ' num2str(MW)]);
However, I keep getting this error
Undefined function 'foodwastes' for input
arguments of type 'double'.
Any ideas what I can do to fix this? Thanks
  1 comentario
Walter Roberson
Walter Roberson el 9 de Nov. de 2015
Are you storing the code in foodwastes.m in a directory that is on your MATLAB path?

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by