0
点赞
收藏
分享

微信扫一扫

matlab第一次学习成果

捌柒陆壹 2022-03-16 阅读 81

1.MATLAB简介

在开始总结自己的一天的matlab收获之前,先来介绍一下matlab的用途:

作为一种功能强大的数学软件,matlab是参加数学建模比赛的学者必备的数学技能。

2.2022/3/15学习成果:

1.脚本文件

今天开始系统学习matlab,给大家分享一下今天的收获:

今天主要是了解一下matlab的基础性用法:

在matlab中,若直接在命令行窗口输入代码,则是输入一行运行一行,无法像在python和C语言中那样输入大量代码后再进行运行,于是我们可以运用脚本文件,通过新建脚本文件来实现输入大量代码最后一次性运行和检验。

注意 :将脚本文件保存至当前文件夹(Current Folder),保证可以被matlab搜索到。

在脚本文件中点击运行或直接按键盘上的F5键,则可以在matlab中运行脚本文件。

合理运用脚本文件可以帮助我们快速检索代码是否正确,从而为我们节省大量时间。

2.变量

在matlab中,我们设置的变量只能以字母开头,但后面可以加数字及特殊字符,但在matlab中,设置变量时需要注意以下几点:

1.大小写不同的变量是不同的变量

2.变量名长度有上限(可以通过输入namelengthmax 来查matlab中变量的最长长度)

3.命名变量时最好采用一些有意义的字母来命名。如:Text_Variable_Name_1或TextNariableName1,但在实际操作matlab中,尽量采用一种命名方式,比如都加下划线或者都不加,否则可能会影响到matlab的可读性。

4.尽量不要用函数名来命名变量

 5.仅输入clear 则会删除所有变量,但如果输入clear ***(一个变量名)则会删除特定变量

3.初识函数

matlab中的函数运算优先级:小括号里的内容>乘方>负号>乘除>加减

help elfun..........................................帮助查询所有函数类型

>> help elfun
  Elementary math functions.
 
  Trigonometric.
    sin         - Sine.
    sind        - Sine of argument in degrees.
    sinh        - Hyperbolic sine.
    asin        - Inverse sine.
    asind       - Inverse sine, result in degrees.
    asinh       - Inverse hyperbolic sine.
    cos         - Cosine.
    cosd        - Cosine of argument in degrees.
    cosh        - Hyperbolic cosine.
    acos        - Inverse cosine.
    acosd       - Inverse cosine, result in degrees.
    acosh       - Inverse hyperbolic cosine.
    tan         - Tangent.
    tand        - Tangent of argument in degrees.
    tanh        - Hyperbolic tangent.
    atan        - Inverse tangent.
    atand       - Inverse tangent, result in degrees.
    atan2       - Four quadrant inverse tangent.
    atan2d      - Four quadrant inverse tangent, result in degrees.
    atanh       - Inverse hyperbolic tangent.
    sec         - Secant.
    secd        - Secant of argument in degrees.
    sech        - Hyperbolic secant.
    asec        - Inverse secant.
    asecd       - Inverse secant, result in degrees.
    asech       - Inverse hyperbolic secant.
    csc         - Cosecant.
    cscd        - Cosecant of argument in degrees.
    csch        - Hyperbolic cosecant.
    acsc        - Inverse cosecant.
    acscd       - Inverse cosecant, result in degrees.
    acsch       - Inverse hyperbolic cosecant.
    cot         - Cotangent.
    cotd        - Cotangent of argument in degrees.
    coth        - Hyperbolic cotangent.
    acot        - Inverse cotangent.
    acotd       - Inverse cotangent, result in degrees.
    acoth       - Inverse hyperbolic cotangent.
    hypot       - Square root of sum of squares.
    deg2rad     - Convert angles from degrees to radians.
    rad2deg     - Convert angles from radians to degrees.
 
  Exponential.
    exp         - Exponential.
    expm1       - Compute exp(x)-1 accurately.
    log         - Natural logarithm.
    log1p       - Compute log(1+x) accurately.
    log10       - Common (base 10) logarithm.
    log2        - Base 2 logarithm and dissect floating point number.
    pow2        - Base 2 power and scale floating point number.
    realpow     - Power that will error out on complex result.
    reallog     - Natural logarithm of real number.
    realsqrt    - Square root of number greater than or equal to zero.
    sqrt        - Square root.
    nthroot     - Real n-th root of real numbers.
    nextpow2    - Next higher power of 2.
 
  Complex.
    abs         - Absolute value.
    angle       - Phase angle.
    complex     - Construct complex data from real and imaginary parts.
    conj        - Complex conjugate.
    imag        - Complex imaginary part.
    real        - Complex real part.
    unwrap      - Unwrap phase angle.
    isreal      - True for real array.
    cplxpair    - Sort numbers into complex conjugate pairs.
 
  Rounding and remainder.
    fix         - Round towards zero.
    floor       - Round towards minus infinity.
    ceil        - Round towards plus infinity.
    round       - Round towards nearest integer.
    mod         - Modulus (signed remainder after division).
    rem         - Remainder after division.
    sign        - Signum.

~~~ 而直接输入help ***(函数名)可以帮助我们了解这个函数的详细用法介绍;或者将光标停留在函数名中间,按F1也可以实现相同功能

~~~输入函数名的前几个字母,按tab键可以帮助搜索函数

4.随机数

输入rand() 可以使我们得到一些随机数,可以用于我们的随机试验

rng(1)可以帮我们重置随机数,令下次rand()运行后的结果与我们第一次运行时的结果相同

(每次重启matlab时也会重置随机数)

但是,如果我们输入rng('shuffle')则不会重置随机数,可以确保我们每次的随机试验得到不同的结果。

5.其他的零碎知识点 

pause................................让matlab进入待机状态

CTRL+C............................结束待机状态,开始新任务(当程序比较复杂时可以用这个来结束                                                                                                         matlab的运行,进行别的运算)

format long/short................输出长的(16位字符)或短的(5字符)结果

pi.........................................matlab中的圆周率

format compact....................减少空行

format loose..........................增加空行

按向上方向键........................查询历史输入

3e8/3E8/3d8/3D8..................表示科学计数法3*10^8

如果输入的式子太长,可用...进行换行

i,j.............................................均表示复数

3.总结

第一次写博客,也是初学matlab,以上内容如有什么错误或不当之处,烦请指正。

举报

相关推荐

第一次go学习

sql第一次

记录第一次

第一次打卡

【学习记录】第一次随堂测

jQuery第一次课

假期第一次总结

0 条评论