Search code examples
matlabsimplification

What is the proper way to simplfy the expression 'x' plus 'x' in MATLAB?


I have a very simple question: I'm trying to simplify the expression x + x to get the answer 2x in MATLAB but I'm having a hard time figuring out the proper format and I don't know what to search in the documentation files for an answer.


Solution

  • EDIT:

    From the comments below, it looks like you need the symbolic toolbox. A basic example can be found in this answer. Once x is set to be a symbolic variable, x+x should give you 2*x.

    Original answer:

    Your question, as it stands, is not very clear. I'll interpret your question to mean the following:

    Mathematically, x+x is 2x. How do I write 2x in MATLAB?

    In MATLAB, arithmetic operations need to be explicitly stated. The operator for scalar multiplication is * and you would write the above as 2*x. Here is the documentation for the various arithmetic operations, and their rules & syntaxes. For the most part, if you're familiar with linear algebra, you'll find MATLAB pretty easy to use.

    If I'm mistaken and you meant something else, please edit your question to clarify (and/or leave a comment here) and I'll update my answer.