How can I define f(x) = x/x in MATLAB (Symbolic Computation)

3 views (last 30 days)
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!

Accepted Answer

Star Strider
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
epsilonxe
epsilonxe on 21 May 2014
Thank you very much for your answers. This is what I want.
I missed the point that x/x is symbolically 1. Thanks again for this prompt.
Moreover I still have one more question:
Is there a method to avoid automatic simplification on "sym/syms" commands?
(just want to store the value "as is" via sym/syms)
Star Strider
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.

Sign in to comment.

More Answers (1)

Sean de Wolski
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?
  1 Comment
epsilonxe
epsilonxe on 21 May 2014
x/x is not equal to 1 when x is only zero.
Please consider the following:
Let f(x) = x/x and g(x) = 1 then domains of f and g are R - {0} and R respectively.
The automatic simplification in "sym/syms" may leads to lose some info.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!