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

6 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Walter Roberson
Walter Roberson il 10 Giu 2025
Modificato: Walter Roberson il 10 Giu 2025
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 Commenti
Walter Roberson
Walter Roberson il 10 Giu 2025
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 il 10 Giu 2025
Oh wow okay, good to know. Reframing it fixed it, thank you!

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by