Using latex command with anonymous functions
Mostra commenti meno recenti
I want to convert a bunch of simple symbolic expressions to latex
e.g.,
syms x;
B = @(x)B(x)
latex(diff(B,x)) produces latex output
but
latex(B(x)) produces an error.
Of course, if I had
B = sym('B(x)')
latex(B(x))
would do what I want it to do, i.e., output B(x) but then
latex(B(y))
would produce an error
Risposte (6)
Alexander
il 14 Ago 2012
In R2012a I can do this:
>> syms x y B(x)
>> latex(B(x))
ans =
B\!\left(x\right)
>> latex(B(y))
ans =
B\!\left(y\right)
>> latex(diff(B(x)))
ans =
\frac{\partial}{\partial x} B\!\left(x\right)
1 Commento
Oleg Komarov
il 14 Ago 2012
Modificato: Oleg Komarov
il 15 Ago 2012
I like this approach.
Walter Roberson
il 13 Ago 2012
Perhaps
latex(char(B(x)))
Matt Fig
il 13 Ago 2012
B = sym('B(x)');
latex(B)
latex(subs(B,'x','y'))
Oleg Komarov
il 13 Ago 2012
Interesting case, do you define B in a recursive way on purpose?
However the error is clear, B doesn't exist at the moment of the call B(x).
To make it more clear:
syms x
f = @(input) B(input);
f(x)
Undefined function 'B' for input arguments of type 'sym'.
Error in @(input)B(input)
Categorie
Scopri di più su Code Performance in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!