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 CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

태그

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by