char produces ln instead of log

2 vues (au cours des 30 derniers jours)
Sergei
Sergei le 26 Mar 2012
I have a system of symbolic equations f, one of which contains log(x). When I try to evaluate it with eval(f), it calls at some point char(x), which replaces "log" with "ln", and matlab cannot process it. Did anybody experience a similar problem? Is there a workaround? Thanks!
  2 commentaires
Kevin Holst
Kevin Holst le 26 Mar 2012
Have you tried eval('char([102 108 105 112 108 114 40 39 116 105 120 101 39 41])')?
Why are you needing to use eval in this code? Could you post some of your code?
Sergei
Sergei le 26 Mar 2012
Modifié(e) : Walter Roberson le 30 Oct 2023
I am using a code written by someone else. You can find it here:
You can, for example, run "Example 1" (by running neoclassical_model_run.m).
The eval part appears in num_eval.m file.
Typically, I found this program to work well. However, I have recently tried to use it to solve a model where it gave me this trouble (but also not always, only for some parameter combinations).

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 26 Mar 2012
Don't eval() a symbolic equation. There are too many subtle syntax and function differences.
If you have all of the values needed for the symbolic equation, you can subs() the values into the equation.
If you will be evaluating the same symbolic equation repeatedly with numeric values substituted for all of the variables, use matlabFunction() to transform the symbolic function to an anonymous function.

Plus de réponses (0)

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by