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

6 visualizaciones (últimos 30 días)
Elena
Elena el 10 de Jun. de 2025
Comentada: Elena el 10 de Jun. de 2025
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 10 de Jun. de 2025
Editada: Walter Roberson el 10 de Jun. de 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 comentarios
Walter Roberson
Walter Roberson el 10 de Jun. de 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 el 10 de Jun. de 2025
Oh wow okay, good to know. Reframing it fixed it, thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by