Why does my code return 'Empty sym: 0-by-1'?

6 ビュー (過去 30 日間)
Elena
Elena 2025 年 6 月 10 日
コメント済み: Elena 2025 年 6 月 10 日
Currently working through chapter 12 in the third edition of MATLAB for Engineers by Holly Moore. I was trying to replicate example 12.1, which shows how to solve the reaction rate constants equation for Q: using symbolic variables and the solve equation. After a few tries, I copied the given code word for word but every time I run it, it returns 'Empty sym: 0-by-1' instead of the result the book shows, which is
ans =
-R*T*log(k/k0)
My input is:
syms k0 Q R T
k = k0*exp(-Q/(R*T)) == 0;
Q0 = solve(k,Q)
The book calls for:
X = sym('k = k0*exp(-Q/(R*T))')
solve(X,'Q')
I tried both, but neither returns what it's supposed to as far as I can tell

採用された回答

Walter Roberson
Walter Roberson 2025 年 6 月 10 日
編集済み: Walter Roberson 2025 年 6 月 10 日
You have misframed k = k0 * exp(-Q/(R*T)) . Written as an equation equalling 0, it would be eqn = k - k0 * exp(-Q/(R*T)) == 0
syms k k0 Q R T
eqn = k - k0 * exp(-Q/(R*T)) == 0
eqn = 
solve(eqn, Q)
ans = 
The way you had it was trying to solve k0*exp(-Q/(R*T)) == 0 for Q. That has the trivial solution k0 = 0. Otherwise divide by sides by k0 to get exp(-Q/(R*T)) == 0, so log(exp(-Q/(R*T)) == log(0) so -Q/(R*T) == -inf . That in turn has the solution "Q non-negative, R or T or both are 0", or the solution "Q is inf, R and T both positive or both negative" or "Q is -inf, R and T opposite signs". There might be additional solutions in complex values. solve() could potentially have returned a piecewise() of all of the possibilities.
  2 件のコメント
Walter Roberson
Walter Roberson 2025 年 6 月 10 日
The sym() version is old-style, not supported since roughly R2017b. The closest modern approach to that would be
X = str2sym('k = k0*exp(-Q/(R*T))')
X = 
solve(X,sym('Q'))
ans = 
Elena
Elena 2025 年 6 月 10 日
Oh wow okay, good to know. Reframing it fixed it, thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumeric Solvers についてさらに検索

タグ

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by