# Why getting some strange fractions? The code is simple and correct,maybe.

12 views (last 30 days)

Show older comments

why these fraction?

nuove_pp(reag+i) -> ..and.. -> nuove_pp ->

nuove_pp = 1×4

14.6794 9.7862 44.0381 39.1449

nuove_pp

reag

prod

cs

prodotti_numeratore=1;

for i=1:prod

prodotti_numeratore = prodotti_numeratore.*((nuove_pp(reag+i)+cs(reag+i)*x)^cs(reag+i)) ;

end

reagenti_denominatore=1;

for i=1:reag

reagenti_denominatore = reagenti_denominatore*((nuove_pp(i)-cs(i)*x)^cs(i)) ;

end

Q=prodotti_numeratore /reagenti_denominatore

equ= Q == K_P;

sol=double(solve(equ,x,'Real',true))

##### 0 Comments

### Answers (6)

Stephan
on 17 Sep 2018

Edited: Stephan
on 17 Sep 2018

Hi,

if you calculate symbolic equation, the calculated values (like factors for example) in symbolic equations are represented exactly, which means that they look like this.

double(a)

If you create function handles from your symbolic equation the values will be converted to double automatically.

A way for more precision than double is vpa like Star Strider suggested in his answer. If you want to solve symbolic equations numeric have a look at vpasolve.

Best regards

Stephan

##### 0 Comments

Luca
on 18 Sep 2018

##### 6 Comments

Stephen23
on 20 Sep 2018

That's all.

nuove_pp = 1×4

14.6794 9.7862 44.0381 39.1449

reag=2;

prod=2;

cs=[1 1 1 1];

prodotti_numeratore=1;

for i=1:prod

prodotti_numeratore = prodotti_numeratore.*((nuove_pp(reag+i)+cs(reag+i)*x)^cs(reag+i)) ;

end

reagenti_denominatore=1;

for i=1:reag

reagenti_denominatore = reagenti_denominatore*((nuove_pp(i)-cs(i)*x)^cs(i)) ;

end

Q=prodotti_numeratore /reagenti_denominatore

equ= Q == K_P;

Luca
on 18 Sep 2018

##### 1 Comment

Walter Roberson
on 19 Sep 2018

Luca
on 20 Sep 2018

##### 1 Comment

Walter Roberson
on 20 Sep 2018

Your code prompts four times for "Inserisci il coefficiente stechiometrico del reagente". This values get displayed directly on your sample output diagrams as "cs" just above "Q". It looks like the answers to each of those should be 1 .

Your code then prompts two times for "Assegnazione moli di reagente" and two times for "Assegnazione moli di prodotto". The English translation of that is "Assignment of moles of reagent", and "Assignment of moles of product" which appears to be questions about mole values that would be responded to with mol quantities, rather than a question about partial pressures. These values get displayed in your code as moli_reag and moli_prod a full page above the portion of the code that you have posted images of.

I need you to pick one particular set of "Inserisci il coefficiente stechiometrico del reagente" values and one particular set of "Assegnazione moli di reagente" and "Assegnazione moli di prodotto" values and tell me what they are. Do not assume that I can read them off of the diagrams: your diagrams are cut off.

This is not hard: just tell me which 8 input values are to be used.

Luca
on 20 Sep 2018

##### 1 Comment

Walter Roberson
on 20 Sep 2018

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!