Can't solve integrate with unknown value

Im doing calculations in isothermal reactors and need to solve an integral with an unknown value (xa):
My code:
fun = @(xa) ( 1 / (k * CA0^2 * (1 - xa)^2 )
solve ( t == CA0 * integral(fun , 0 , xa ) , xa )
Where t is known, CA0 is known , k is known and xa is my unknown
If I solve by hand I get the right equation:
xa = k*CA0*t / (1 + k*CA0*t)
And can easy find my xa, it is not possible to find the right xa with my code.
Can you get: xa = k*CA0*t / (1 + k*CA0*t) from Matlab or an equation similar, which can find my xa?
Values:
CA0 = 2500, t = 13.57 and k = 1.40 * 10^-4
the xa should be 0.826

 採用された回答

Walter Roberson
Walter Roberson 2016 年 11 月 22 日

1 投票

syms k CA0 xa t XA
fun = 1 / (k * CA0^2 * (1 - xa)^2 )
sol = solve(t == int(fun,xa,0,XA), XA, 'ReturnConditions',true)
Then
sol.XA
provided that sol.conditions is true

8 件のコメント

Frank Hansper
Frank Hansper 2016 年 11 月 22 日
Thanks for your suggestion - but when I use the code to generate a equation from it (xa1 = 1 - 1/(k*t*CA0^2 + 1)). It gives xa = 0.999, which is wrong.
Walter Roberson
Walter Roberson 2016 年 11 月 22 日
It gives a symbolic answer involving variables that have not been assigned a valuable. It gives a formula not a numeric value. You would need to substitute values for the symbolic variables to get a numeric value. We would need know what values you are substituting
Torsten
Torsten 2016 年 11 月 22 日
If your commands are exactly the same as Walter's three lines of code, this must be a bug.
Best wishes
Torsten.
Frank Hansper
Frank Hansper 2016 年 11 月 22 日
編集済み: Frank Hansper 2016 年 11 月 22 日
Argh, your code is correct, Walter Roberson! but you forgot to include the CA0 term right after the integral.
Right code:
syms k CA0 xa t XA
fun = 1 / (k * CA0^2 * (1 - xa)^2 )
sol = solve(t == (CA0) * int(fun,xa,0,XA), XA, 'ReturnConditions',true)
sol.XA
Thanks guys, for helping me.
One last thing, can you elaborate on 'ReturnConditions',true, I aint familiar with this?
Walter Roberson
Walter Roberson 2016 年 11 月 23 日
When ReturnConditions is true, then the Conditions field of the returned struct will be a conditional expression. The solution that was given in the other variables is only valid when the conditional expression is true.
As a simple example, if the solution to something was 1/x then the Conditions field returned might be x ~= 0 -- that the solution 1/x just is not valid when x == 0
Frank Hansper
Frank Hansper 2016 年 11 月 23 日
I see, thanks for the explanation and your time.
I have nothing more at the moment and consider this theard answered.
Karan Gill
Karan Gill 2016 年 11 月 23 日
Frank, regarding "ReturnConditions", did you try looking up the documentation for solve at https://www.mathworks.com/help/symbolic/solve.html ?
Frank Hansper
Frank Hansper 2016 年 11 月 24 日
Yes and I must say, I had a brain fart - I thought Matlab would return the solution with ''it's'' conditions of the solution. ex. Matlab returns what it uses symbolic and what is uses numeric. So I found it unnecessary at first.

サインインしてコメントする。

その他の回答 (1 件)

Torsten
Torsten 2016 年 11 月 22 日

0 投票

Use "int" instead of "integral" for symbolic calculations.
Best wishes
Torsten.

Community Treasure Hunt

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

Start Hunting!

Translated by