首页系统综合问题26「研读分享」聊一聊Mathematica中的基本量

26「研读分享」聊一聊Mathematica中的基本量

时间2023-08-17 19:08:59发布分享专员分类系统综合问题浏览261

今天小编给各位分享anumeric的知识,文中也会对其通过26「研读分享」聊一聊Mathematica中的基本量和Mathematic是干什么的?等多篇文章进行知识讲解,如果文章内容对您有帮助,别忘了关注本站,现在进入正文!

内容导航:

  • 26「研读分享」聊一聊Mathematica中的基本量
  • Mathematic是干什么的?
  • mathematica中的基本数学输入怎么使用
  • 如何系统的学习Mathematica
  • 一、26「研读分享」聊一聊Mathematica中的基本量

    分享兴趣、传播快乐、增长见闻、留下美好,大家好,这里是LearningYard学苑,今天小编为大家带来文章:聊一聊Mathematica中的基本量。

    首先,自计算机语言诞生以来,人类使用计算机进行一些特定的工作时,往往需要将我们的需求转化为计算机能识别的语言。我们用Mathematica进行数学分析或者画图时,需要输入一段命令(指令),今天我们要讲的就是这些命令都是如何构成以及尝试分析构成命令的那些量的逻辑。

    通过查看我导师分享的mathematica软件参考书籍,当我们讨论mathematica中有哪些基本量时,参考的回答如下:数、变量、函数、表、表达式、常用的符号。

    附上今日推文的思维导图。

    图0

    01 数

    Mathematica中如果结果为整数,则在out中会尽数展示所有的数字。

    对于有理数,mathematica一般用分数展示一个除不尽的数;对于实数,mathematica将其表示为小数形式或者指数形式;复数是由实部和虚部组成,实部和虚部可以用整数、实数、有理数表示。在Mathematica中,用I 表示虚数单位如。

    图1

    要实现数据类型的转换,可以参考以下函数:

    N[x] 将x转换成实数

    N[x,n] 将x转换成近似实数,精度为n

    Rationalize[x] 给出x的有理数近似值

    Rationalize[x,dx] 给出x的有理数近似值,误差小于dx

    建模中常用到的数学常数有:

    图2

    02 变量

    2.1有效的变量命名格式法

    为了与mathematica自带的函数区别开来,变量名称首字母用小写,除了使用字母,还可以使用字母加数字等命名格式。

    2.2如何给变量赋值

    不管是单变量赋值还是多变量赋值,都可以采用“变量名=数、图片、公式等”的格式。特别的,对多个不同的变量赋值时,要先用{}将需要赋值的变量框起来。

    图3

    当需要清除变量的值时,用用=.清除它的值,如果变量本身也要清除用函数Clear[],例如:

    图4

    2.3对于一个给定的表达式,想要观察当变量x变化为不同的值时,表达式值的变化,可以用到变量替换的表达公式,例如:

    图5

    03 函数

    3.1mathematica中那些自带的函数

    下面这张图列举了一般的函数,感兴趣的小伙伴可以自行到mathematica中的参考文档里查找更多。

    图6

    3.2如何在mathematica中自定义函数

    当我们求解一个具体的模型时,自定义函数可以说是必选项。首先,我们一起了解一下最基本最简单的函数定义法-即时定义函数法。

    语法如下:f[x_]=expr函数名为f,自变量为x,expr是表达式。在执行时会把expr 中的x都换为f的自变量x (不是x_ )。函数的自变量具有局部性,只对所在的函数起作用。函数执行结束后也就没有了,不会改变其它全局定义的同名变量的值。

    图7

    下面跟大家分享一下,延迟定义函数的方法。延迟定义函数从定义方法上与即时定义的区别为 “=“ 与”:=“延迟定义的格式为f[x_]:=expr其他操作基本相同。那么延迟定义和即时定义的主要区别是什么?即时定义函数在输入函数后立即定义函数并存放在内存中并可直接调用。延时定义只是在调用函数时才真正定义函数【1】。总之两种方法都可以,使用哪一种大家凭喜好决定。

    上述定义的函数比较简单,只含有一个表达式。在日常的学习环境中,特别是饭饭现在在学运筹学,有很多分段函数。那么分段函数如何定义呢。根据分段函数的内涵,我们可以想到用if条件语定义。具体例子如下:

    图8

    对于上面这个分段函数,我们先用if语句来构思一下。

    If语句的调用格式为If[条件,值1,值2],如果条件成立取”值1”,否则取”值2”

    运用到本案例中,我尝试做一做:

    图9

    在点击enter+ctrl运行函数表达式时,三种方式展现的结果不一样。原因在于用=还是用:=,在运行时是有差别的。之后随便带入两个数,验证一下,结果是只有命令方式2可以输出正确的结果。

    图10

    当然,我们也可以不用if语句来定义,可以在g[x_]上适当调整,达到我们想要的结果。操作如下图中的命令9:

    参考教程,我们可以使用条件运算符号,基本格式为:f[x_]:=expr/;condition ,当condition条件满足时才把expr赋给f(x)。

    图11

    碎碎念->结合变量的替换公式和分段函数的定义,我们可以看出在mathematica中使用“/”的场景通常是需要对某个表达式或者表达式中的变量设置运行条件或者用其他元素来代替原表达式中的某一部分(这一点,也可以在处理表达式命令格式中体现,具体信息请继续看下去)。

    另外,在本次分段函数的定义中,我发现只有用:=定义的函数(如g2[x_])才能被mathematica正确计算。画图验证如下:

    图12

    04 表

    4.1新建一个表

    首先,我们先了解一下mathematica中表的定义——将一些相互关联的元素放在一起,使它们成为一个整体。既可以对整体操作,也可以对整体中的一个元素单独进行操作。在Mathematica中这样的数据结构就称作表(List)。表{a,b,c}表示一个向量;表{{a,b},{c,d}}表示一个矩阵【1】。

    对于元素比较少的表,可以采用直接输入法;对于元素比较多的表,可以用Table函数法

    如:

    图13

    4.2提取子表

    这一步比较统一,直接用公式“表名[[提取的子表序号]]”。例子如下:

    图14

    特别的,如果表被输出为矩阵格式,则无法用“表名[[提取的子表序号]]”完成提取子表工作。

    图15

    需要提取矩阵中的元素时,参考下面这个案例。

    图16

    05 表达式

    表达式是由常量、变量、函数、命令、运算符和括号等组成,它最典型的形式是f[x,y]【1】。

    我们在建模时需要用到大量表达式,如定义供应商的利润=总收益-总成本。需要设置三个变量,并且用表达式定义它们的关系。

    5.1表达式的相关操作

    首先,遇到复杂的表达式,常常需要化简。当我们需要展开某一个表达式时,可以输入相应的命令。

    图17

    5.2关系表达式和逻辑表达式

    关系表达式的一般形式是:表达式+关系算子+表达式。其中表达式可为数字表达式、字符表达式或意义更广泛的表达式,如一个图形表达式等。在我们实际运用中,这里的表达式常常是数字表达式或字符表达式【1】。

    Mathematica中的关系算子有:

    图18

    有了关系表达式,在循环语句中,我们常常需要用逻辑算子来连接两个关系表达式。这样就形成了一个逻辑表达式。Mathematica中的逻辑算子有:

    图19

    案例如下

    图20

    06 常用符号

    这里不单独提供案例,大家可以参考前面的内容。

    图21

    英文版

    First of all, since the birth of computer languages, when humans use computers to perform certain tasks, they often need to translate our needs into languages that computers can recognize. When we use Mathematica for mathematical analysis or drawing, we need to enter a command (command). Today we are going to talk about how these commands are composed and try to analyze the logic of the quantities that constitute the command.

    By looking at the mathematica software reference books shared by my instructor, when we discuss the basic quantities in mathematica, the answers for reference are as follows: numbers, variables, functions, tables, expressions, commonly used symbols.

    Attach a mind map of today’s tweets.

    01 number

    In Mathematica, if the result is an integer, all numbers will be displayed in out.

    For rational numbers, mathematica generally uses fractions to display an inexhaustible number; for real numbers, mathematica expresses it in decimal form or exponential form; complex numbers are composed of real and imaginary parts. The real and imaginary parts can be integers, real numbers, Rational number representation. In Mathematica, use I to represent the imaginary unit such as.

    figure 1

    To achieve data type conversion, you can refer to the following functions:

    N[x] convert x to a real number

    N[x,n] converts x into an approximate real number, with a precision of n

    Rationalize[x] gives the rational approximation of x

    Rationalize[x,dx] gives the rational approximation of x, the error is less than dx

    The mathematical constants commonly used in modeling are:

    figure 2

    02 variables

    2.1 Effective variable naming format

    In order to distinguish it from the functions that come with mathematica, the first letter of the variable name is lowercase. In addition to using letters, you can also use the naming format such as letters and numbers.

    2.2 How to assign values to variables

    Regardless of single-variable assignment or multi-variable assignment, the format of "variable name=number, picture, formula, etc." can be used. In particular, when assigning values to multiple different variables, you must first use {} to frame the variables that need to be assigned.

    image 3

    When you need to clear the value of a variable, use =. to clear its value, if the variable itself must be cleared, use the function Clear[], for example:

    Figure 4

    2.3 For a given expression, if you want to observe the change of the expression value when the variable x changes to a different value, you can use the expression formula of variable substitution, for example:

    Figure 5

    03 function

    3.1 those built-in functions in mathematica

    The following picture lists general functions. Interested friends can find more in the reference documents in mathematica.

    Image 6

    3.2 How to customize functions in mathematica

    When we solve a specific model, a custom function can be said to be a must. First of all, let's take a look at the most basic and simple function definition method-instant definition function method.

    The syntax is as follows: f[x_]=expr The function name is f, the argument is x, and expr is an expression. During execution, all x in expr will be replaced by the argument x of f (not x_ ). The argument of a function is local and only affects the function in which it is located. After the function is executed, it will disappear, and will not change the value of other globally defined variables with the same name.

    Figure 7

    Let me share with you the method of delaying the function definition. The difference between the definition method of the delay definition function and the immediate definition is "=" and":=" The format of the delay definition is f[x_]:=expr and other operations are basically the same. So what is the main difference between the delay definition and the immediate definition? Immediately defined function Defines the function immediately after inputting the function and stores it in the memory and can be called directly. The delay definition only really defines the function when the function is called [1]. In short, both methods are okay. You can decide which one to use.

    The function defined above is relatively simple and contains only one expression. In the daily learning environment, especially Fanfan is now learning operations research, there are many piecewise functions. So how to define the piecewise function. According to the connotation of the piecewise function, we can think of using the if conditional definition. Specific examples are as follows:

    Figure 8

    For the above piecewise function, let's first use the if statement to conceive it.

    The calling format of the If statement is If[condition, value 1, value 2], if the condition is true, take "value 1", otherwise take "value 2"

    In this case, I tried to do:

    Picture 9

    When you click enter+ctrl to run the function expression, the three ways show different results. The reason is whether to use = or :=, there is a difference at runtime. After that, just bring in two numbers and verify it. The result is that only command mode 2 can output the correct result.

    Picture 10

    Of course, we can also define without the if statement, and adjust it appropriately on g[x_] to achieve the result we want. Operate the command 9 in the following figure:

    Refer to the tutorial, we can use conditional arithmetic symbols, the basic format is: f[x_]:=expr/;condition, expr is assigned to f(x) only when the condition is satisfied.

    Picture 11

    Sui Sui Nian -> Combining the variable substitution formula and the definition of the piecewise function, we can see that the use of "/" in mathematica usually requires setting operating conditions for a certain expression or variable in the expression or using other Element to replace a certain part of the original expression (this point can also be reflected in the processing expression command format, please continue to read for specific information).

    In addition, in the definition of this piecewise function, I found that only functions defined with: = (such as g2[x_]) can be correctly calculated by mathematica. The drawing verification is as follows:

    Picture 12

    04 Table

    4.1 Create a new table

    First, let's first understand the definition of tables in mathematica-put some interrelated elements together to make them a whole. You can operate on the whole or on an element in the whole individually. In Mathematica, such a data structure is called a list (List). The table {a, b, c} represents a vector; the table {{a, b}, {c, d}} represents a matrix [1].

    For tables with fewer elements, you can use the direct input method; for tables with more elements, you can use the Table function method

    like:

    Figure 13

    4.2 Extract sub-table

    This step is more uniform, directly use the formula "table name [[extracted sub-table number]]". Examples are as follows:

    Picture 14

    In particular, if the table is output in a matrix format, you cannot use "table name [[extracted sub-table number]]" to complete the sub-table extraction work.

    Figure 15

    When you need to extract elements in the matrix, refer to the following case.

    Figure 16

    05 expression

    An expression is composed of constants, variables, functions, commands, operators, and parentheses. Its most typical form is f[x,y][1].

    We need to use a lot of expressions when modeling, such as the definition of supplier profit = total revenue-total cost. Need to set up three variables, and use expressions to define their relationship.

    5.1 Related operations of expressions

    First of all, when encountering complex expressions, it is often necessary to simplify them.

    When we need to expand a certain expression, we can enter the corresponding command.

    Figure 17

    5.2 Relational expressions and logical expressions

    The general form of relational expression is: expression + relational operator + expression. The expression can be a numeric expression, a character expression, or an expression with a broader meaning, such as a graphic expression. In our actual application, the expressions here are often numeric expressions or character expressions [1].

    The relational operators in Mathematica are:

    Figure 18

    With relational expressions, in loop statements, we often need to use logical operators to connect two relational expressions. This forms a logical expression. The logical operators in Mathematica are:

    Figure 19

    The case is as follows

    Picture 20

    06 Commonly used symbols in Mathematica

    Picture 21

    由于篇幅有限,今天的分享就到这里啦

    Due to limited space, that's all for today's sharing

    感兴趣的同学可以留言与小编交流,

    咱们下周见!

    往期精彩:

    参考资料:

    [1]Mathematica8教程.

    [2]田琦师姐的学习文档.

    英文翻译:Google翻译。

    本文由LearningYard学苑整理并发出,如有侵权,请联系删除!

    一、Mathematic是干什么的?

    是说的 mathematica吧。
    Mathematica的符号功能是最强的。且它的运行构架是最优的。符号运算效力与解析能力是最好的(数值运算当然是Matlab最好)。它的构架由核心系统与前端系统构成。两个系统既合作又独立。这个比Matlab的构架都要优秀。它是专为研究人员开发的。至于Maple的符号能力根本就比Mathematica弱很多的。它基本上是为中学生与大学生之学习研发的。不足以进行物理学与技术科学的运演。而Mathematica是最好的物理学科研的工具。Matlab是最好的技术科学数值求解的工具。朋友们应该知了。数值类的数学软件是Matlab最好最全。符号分析类的数学软件是Mathematica最好。

    二、mathematica中的基本数学输入怎么使用

    MathMatica(MMA)软件有四大功能,数值计算、符号运算、绘制图形、程序设计。使用时先打开MMA软件,再打开菜单栏的 文件 / 新建 / 笔记本(Notebook),对未命名的笔记本文件取一个文件名比如“数值计算",然后可在Notebook界面输入需要计算的内容。用MMA进行数值运算就象使用计算器一样,但MMA比任何计算器功能都要强大。例如输入数值计算
    In[15]: 64∧(1/3)
    Out[16] =4
    再比如分解因式 x∧2+3x+2
    In[21]: Factor [x∧2+3x+2]
    Out[22] (x+1)(x+2)
    输入数学符号可用电脑键盘,有的符号键盘没有就需要使用MMA软件中的“数学面板”。特别是虚数单位必须用“数学面板”中的空心i。
    现在看求解线性方程组。
    方法① 对增广矩阵实施初等行变换,使用函数命令为RowReduce。
    方法② 求系数矩阵的逆矩阵。已知线性方程组的矩阵形式是AX=b,若求得系数矩阵A的逆,则有X=A∧(—1)b,求逆矩阵函数命令为Inverse。
    方法③ 使用Solve命令。这个函数是求解代数方程的一般命令,可用于求解一元高次方程,也可用于求解多元线性方程组。方程的等号必须用双等号 “==”。输入格式Solve[{eqns1,eqns2,···},{vars}]。
    方法④ 使用求特解的命令求线性方程组。求特解的函数命令是LinearSolve。
    只要你经常使用MMA软件并专心研究,相信你有个一年半载就会较熟练。

    三、如何系统的学习Mathematica

    零基础的可以看看Wolfram Language Tutorial: A Fast Introduction for Programmers,官方的快速入门,对浩繁的功能选择了最核心的一部份做的极简风格的入门教程,一个小时就入门。2015 年新出了一本An Elementary Introduction to the Wolfram Language by Stephen Wolfram,稍微长一点,系统性一点。

    然后读 Shifrin 的 《Mathematica programming- An Advanced Introduction》,英文能力够的读英文原作。不够的,可以读志愿者翻译的中文版(不完整)。通读一遍裨益良多。

    在有了一定基础后,如果要达到精通,需要长期持续学习,主要是在解决实际问题的过程中学,原因是 Mathematica / Wolfram 语言的内容和功能「 包罗万象」,用了 n 年后你还会有不断发现「惊喜」,而且一个新版本发布出来经常会增加很多新功能(参见:Mathematica 最新版本和旧版本历史)。在解决问题的过程中参考Wolfram Language & System Documentation Center(官方帮助文档),反复看里面的语法说明、专项说明、例子,自己常用的功能就会越来越熟。官方文档里有一部份写成专题的称为「tutorial」,可以挑自己感兴趣的专门拿出来深入学习。

    还可以看Mathematica Stack Exchange上的学习资料表、初学者常见错误,MathCraft.org 整理的参考资料表。这时候只怕学习时间不够用了。还可以经常逛逛Mathematica Stack Exchange,Wolfram Community,关注Wolfram 官方微博@WolframChina,有最新的和 Mathematica / Wolfram 语言相关的信息发布。


    最近写大作业,做SRT,都在用Mathematica,逐渐了解Mathematica的整个构架后,越来越佩服Wolfram的精妙与博大了。对我而言,Mathematica已经不只是一个工具了,也是生活中朝夕相伴的一个朋友。

    其实对Mathematica的了解远谈不上精通,基本算是属于现炒现卖吧,而且国内会用Mathematica的人太少了,连有价值的参考资料都很难见到,大部分时候还是看Mathematica自带的帮助文档(所幸,Mathematica自带的帮助文档相当详尽)。同时我也想能留下一些学习过程中的痕迹,记录和Mathematica在一起的日子。这里标题里写了(1),我希望还能有(2)、(3)…呵呵,尽量时常来更新一下吧。

    我想,第一篇文章就当作序言,大略说明一下目前我对Mathematica的了解,就当作带领大家了解Mathematica的第一步吧。

    (本文中提到的所有程序代码,如未特别说明,均在Mathematica7.0环境下编写运行的)

    Mathematica能做什么?

    国内使用Mathematica的人确实非常少,一提到做数值计算,做模拟仿真,做数学实验,马上就有铺天海地的MATLAB的介绍和学习资料,想要了解Mathematica,实在是太难了。我也一样,我想,若不是当初Amber的介绍,我至今也不会知道Mathematica为何物的。

    刚开始的时候,我也和很多Mathematica的使用者一样,只是将它当作一个高级点的计算器来使用。为什么说它是“高级点”的计算器呢?因为它和你能见到的计算器相比,实在是强大太多了。

    比如计算阶乘,你手中的掌上计算器(甚至windows自带的那个计算器)能算到多少的阶乘?我试过我的CASIO fx-95MS,能算到69的阶乘,但是只用10位有效数字。windows自带的计算器,有32位有效数字,拿来计算50000的阶乘,20秒后计算完成。那么Mathematica表现如何呢?下面是截屏的结果,只用了0.031秒,计算出的结果每一位都是准确的(结果太长,这里只显示了一部分)

    再比如算积分(哎呀呀这可是做微积分习题的终极手段了~),基本上你在微积分课堂中遇到的各种定积分不定积分,曲线积分曲面积分,重积分广义积分,都可以计算(Mathematica的输入有两种方式,一种叫行输入,如下面第一个式子,一种叫二维输入,如下面第二个式子,这两种输入格式没有任何区别,我个人偏好行输入,呵呵;而输出也有不同的格式,默认是是标准模式,也可以采用传统模式来显示)

    再来看看画函数图像,也许这第一个图像没什么稀奇的:

    那再看看这个?对量子物理略懂的同学看出这是什么了吧?(顺带提一句,Wolfram就是量子物理出身的~~)

    当然对一元函数作图实在不能说明什么问题,那么看看对二元函数作图呢?(啊,当年学多元微积分的时候没少恶心过~)关键是,Mathematica里画出函数的三维图形后,还可以直接用鼠标拖曳来旋转视角,下面显示的就是从四个不同视角看的函数图形

    说到解方程,也许没什么稀奇的,但是解微分方程呢?解偏微分方程呢?


    (啊不得不感慨一下,真方便啊~~)

    对需要学习《信号与系统》的同学来说,也许老师上课会教大家用MATLAB来检验作业中各种Z变换,Laplace变换,Fourier变换的结果。其实Mathematica一样可以做到

    学习图论,最烦的也许就是不厌其烦地要画一个图(Graph)了,Mathematica可以帮你做到~~(而且很漂亮)


    罗嗦了那么一大堆,但这些也不过是Mathematica的很少一部分的内容。我想,看了上面的介绍,对Mathematica也有了一点初步的了解了吧。那么,敬请期待,下回分解

    to be continued...

    关于anumeric的问题,通过《mathematica中的基本数学输入怎么使用》、《如何系统的学习Mathematica》等文章的解答希望已经帮助到您了!如您想了解更多关于anumeric的相关信息,请到本站进行查找!

    爱资源吧版权声明:以上文中内容来自网络,如有侵权请联系删除,谢谢。

    anumeric
    美拍设置可以取消关注吗?美拍设置取消关注的操作步骤有哪些? 罗技宏怎么设置?详细教程让你轻松上手