The first chapter of MATHEMATICA CORE Language: Learning to calculate

Source: Internet
Author: User

Blog has moved! Please go to http://gqqnbig.me/?p=120 to read this article.using previous results
  • %: Last Result
  • %%: Last Result
  • % % ?          k : First k Results
  • %n: Out[n] Results of output


The official name of% is out. You can find this information by entering% in the Mathematica help browser.

Defining Variables
  • x=value: Assigns value to the variable x.
  • x=y=value: Assigns value to the variable x and Y.
  • x=.Or Clear[x] : Clears the variable x from memory.

Keep in mind that variables are permanent unless you clear them. It is recommended that you run out of variables and remove them manually.

Variable name is not limited in length, but cannot start with a number because 2x means 2 times x. After testing, the variable name can be Chinese, grammar hints are also supported.

Mathematica's built-in functions use the Uppercamel naming method (first letter capitalized). To avoid conflicts with built-in functions, we recommend that the user function begin with a lowercase letter.

Please note the following points:

  • x yRepresents x multiplied by Y.
  • xyRepresents the XY variable.
  • 5 xRepresents 5 times X.
  • x^2 yRepresents (x^2) Y.
symbol substitution is a number

Transform rule x->3 means that the symbol x is substituted for the number 3. The expression can be applied to transform rules, the syntax is expr/. Rule (where expr is an expression, rule is a variation,/.) is called replace operator ).

The transformation rule itself is an expression, or it can be assigned to a variable, which is then involved in the transformation process.

Or

This uses the% function in the previous section.

expr /. {x->xval, y->yval}Used to perform multiple substitutions.

If you want X to always be replaced with a value, then use the assignment syntax, such as x=3, x=fibonacci[10].

Mathematica uses lazy evaluation strategies, and if a variable (symbol) is an expression or a number, it is replaced with a number when evaluated, and if the variable is not defined, it is a symbol, "forget it." Therefore, it is important to define whether a variable is already defined. Remember to use x= often for "garbage collection."

four kinds of brackets
  • (term): Parentheses are used to group
  • f[x]: square brackets substituting symbols into functions
  • {a,b,c}: Curly braces Construct list
  • v[[i]]: Both brackets take the list element
Multiple Actions

    • EXPR1;EXPR2;EXPR3: Performs multiple operations to output the return value of the last operation.
    • EXPR1;EXPR2: Performs multiple operations and does not output.
    • EXPR;: Executes expr, not output.

Even if the previous operation ends with a semicolon, its return value is saved in out, i.e. we can get its value in%.

in[2]:=  x=67-5;in[3]:=  %out[3]=  62

The first chapter of MATHEMATICA CORE Language: Learning to calculate

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.