How can I define f(x) = x/x in MATLAB (Symbolic Computation)
3 views (last 30 days)
Show older comments
I try with these commands
x = sym('x');
f(x) = sym('f(x)');
f(x) = x/x;
and
f(x) = sym('x/x');
, and both of them produce
f(x) = 1
(yes.. for every real x included 0)
The question is how I can avoid the pre-evaluation in the command "sym", or there exists another way to handle this problem.
Thank you very much!
0 Comments
Accepted Answer
Star Strider
on 20 May 2014
I’m obviously missing something in your post. Wouldn’t (x/x)=1 for all x under any conditons?
4 Comments
Star Strider
on 21 May 2014
My pleasure!
The various MATLAB Toolboxes still teach me about them. The occasional version differences keep it interesting.
I’m not aware of a way to automatically suppress it, since simplifying expressions is likely the reason most people use the various symbolic engines. I believe that it (and others like Maple and Mathematica) automatically simplifies to an extent.
I experimented just now with the assume command, and got a very interesting result:
syms f(x)
assume(x == 0)
f(x) = x/x
g = symfun(x/x, x)
In this experiment, f and g both evaluate to 1, even with x ‘set’ to zero. I suggest you report this as a bug.
More Answers (1)
Sean de Wolski
on 21 May 2014
MuPad can handle a function like x/x without automatic simplification. I'm not sure why you want this though. Why do you care about it, is it just for display or something else?
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!