拟合与插值
type
status
date
slug
summary
tags
category
icon
password
Property

 

一元多项式拟合:polyfit()

使用polyfit(x, y, n)函数对数据xy进行n次多项式拟合.
notion image
函数
type
status
date
slug
summary
tags
category
icon
password
Property

与其他语言相似,MATLAB也可以定义函数.与脚本类似,函数可以被存入函数名.m文件中,也可以以函数句柄的形式定义在内存中.

内置函数

可以使用which命令查看内置函数源代码文件的位置,与edit命令结合可以查看内置函数的源代码.
运行下面语句可以打开MATLAB内置的mean函数的源文件:
可以在编辑器中看到mean函数的源代码如下:
notion image

函数名.m文件形式定义函数

数字和矩阵运算
type
status
date
slug
summary
tags
category
icon
password
Property

算数学表达式

  • MATLAB常见运算符有: +/^.
  • 数学表达式被计算后,其值被存入变量ans.
  • 运算的优先级规则:
    • 同等优先级下从左向右运算.
    • 优先级顺序(从高到低)
        1. 括号()
        1. 乘方^
符号运算
type
status
date
slug
summary
tags
category
icon
password
Property

创建符号变量

创建符号数字

使用sym函数可以创建符号数字.使用符号数字可以精确地保存无理数,不会产生误差
将无理数保存为符号数字可以避免将其转换为浮点数的误差:
  1. 使用符号数字计算sin(π)
    1. 使用符号数字计算
      结构化编程
      type
      status
      date
      slug
      summary
      tags
      category
      icon
      password
      Property

       
      notion image

      流程控制语句和逻辑运算符

      与大多数编程语言相同,MATLAB有以下流程控制语句:
      流程控制语句
      作用
      if, elseif, else
      若if语句为真,则执行子句
      数值的微分和积分
      type
      status
      date
      slug
      summary
      tags
      category
      icon
      password
      Property

      数值微分

      求差分:diff()

      notion image
      使用diff(X, n)计算向量Xn阶差分,n默认为1.

      求导数:diff(y)./diff(x)

      使用导数的定义
      数据的导入和导出
      type
      status
      date
      slug
      summary
      tags
      category
      icon
      password
      Property

       
      MATLAB支持的文件类型如下:
      文件内容
      扩展名
      读取文件的函数
      写入文件的函数
      MATLAB数据
      *.mat
      load
      save
      Excel表格
      *.xls*.xlsx
      xlsread
      xlswrite
      空格分隔的数字
      *.txt
      load
      save

      读写MATLAB格式的数据

      多项式的微分和积分
      type
      status
      date
      slug
      summary
      tags
      category
      icon
      password
      Property

      使用MATLAB表示多项式

      使用向量表示多项式

      在MATLAB中,多项式可以用向量表示,向量中的元素为多项式的系数(降幂排序):第一位为多项式最高次项系数,最后一位为常数项.
      例如多项式:
      可以用向量p = [1 0 -2 -5]表示.

      多项式求值:polyval()

      使用polyval(p, x)可以计算多项式px的每个点处的值.
      基础知识及变量
      type
      status
      date
      slug
      summary
      tags
      category
      icon
      password
      Property

       

      MATLAB命令

      使用行尾;抑制输出:在一行命令后使用;抑制输出,否则运算结果将被显示在终端上
      常用命令:
      notion image
      常用快捷键
      notion image
       
      数据类型
      type
      status
      date
      slug
      summary
      tags
      category
      icon
      password
      Property

      notion image
      notion image
       

      判断变量数据类型的函数

      下列函数可以对变量类型进行判断:
      统计
      type
      status
      date
      slug
      summary
      tags
      category
      icon
      password
      Property

      描述性统计(Descriptive Statistics)

      描述性统计主要研究数据的中心趋势(Central Tendency)和变异(Variation).
      notion image

      中心趋势(Central Tendency)

      notion image
      notion image
      下列函数绘制统计图表:
      CSS
      type
      status
      date
      slug
      summary
      tags
      category
      icon
      password
      Property
       

      CSS

      CSS(Cascading Style Sheet):层叠样式表语言。
      CSS的作用是:修饰HTML页面,设置HTML页面中的某些元素的样式,让HTML页面更好看。HTML还是主体,CSS依赖HTML。CSS的存在就是修饰HTML,所以新建的文件还是xx.html文件。
       

      在HTML页面中嵌套使用CSS的三种方式

      内联定义方式

      在标签内部使用style属性来设置元素的CSS样式,语法格式:<标签 style="样式名:样式值;样式名:样式值;样式名:样式值;..."></标签>
      notion image