百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术资源 > 正文

学会matlab,就多了一个科研小助手

moboyou 2025-04-15 13:12 29 浏览


Matlab 介绍——Introduction to Matlab


分享兴趣,传播快乐,增长见闻,留下美好。

亲爱的您,

这里是LearingYard学苑!

今天小编为大家带来matlab介绍

欢迎您的用心访问!

本期推文阅读时长大约6分钟,请您耐心阅读。


Share interest, spread happiness, increase knowledge, and leave beautiful.

Dear you,

This is the LearingYard Academy!

Today, the editor brings you an introduction to matlab

Welcome your visit!

This tweet usually takes about 6 minutes to read, please read it patiently.


#01本期主题介绍

The topic of this issue


如果您学会使用Matlab,

将有一个科研小助手,做事更轻松!

本期话题将对matlab做一个基础介绍。

Matlab的功能多样,

这里介绍一下Matlab“入门级”的基本功能,

目的是给没有接触过Matlab的朋友学习参考。

所以,请感兴趣的朋友和小编开启学习Matlab的旅程吧!

If you can use Matlab, you will have an additional research assistant.

Do things more easily!

The topic of this issue will do a tweet introduction to matlab.

The functions of Matlab are quite diverse,

Here is an introduction to the basic functions of Matlab "entry level",

The purpose is to learn reference for friends who have not contacted Matlab.

So,

Please open with interested friends and editors

Let's get to know the journey of Matlab!


#02Matlab软件介绍

Matlab software introduction

MATLAB 是美国MathWorks公司出品的商业数学软件,用于算法开发、数据可视化、数据分析以及数值计算的高级技术计算语言和交互式环境

MATLAB is a commercial mathematical software produced by MathWorks, a high-level technical computing language and interactive environment for algorithm development, data visualization, data analysis, and numerical calculation.


主要用途:

(1)数值和符号计算;
(2)绘图;

(3)工具箱(Toolbox),分为功能性和学科性两种类。


使用技巧:Help

输入help funname (函数名),即可以得到函数的相关帮助信息。

The main purpose:

(1) Numerical value and symbol calculation;

(2) Drawing;

(3) Toolbox (Toolbox) is divided into two categories: functional and disciplinary.

Use skills: Help

Enter help funname (function name) to get help information about the function.


#03Matlab基础界面介绍

Matlab basic interface introduction


1.Matlab的基础界面The basic interface of Matlab


1)菜单工具栏

2)文件目录

3)命令窗口:交互式地控制Matlab。比如,简单计算,函数命令测试等。

4)数据区:命令中使用的变量、导入的数据、执行的脚本后的数据都会显示在此处。

5)代码编辑区:编辑代码,按菜单栏“运行”Matlab便可执行。


1) Menu toolbar

2) File directory

3) Command window: Control Matlab interactively. For example, simple calculation, function command test, etc.

4) Data area: The variables used in the command, the imported data, and the data after the executed script will all be displayed here.

5) Code editing area:Edit the code and press "Run" Matlab in the menu bar to execute it.

#04Matlab基本使用介绍

Introduction to the basic use of Matlab

1.命令窗口的使用(绘制正弦曲线和余弦曲线)

The use of the command window (drawing sine curve and cosine curve)

操作: 在命令窗口输入

x=[0:0.5:360]*pi/180;plot(x,sin(x),x,cos(x));

Operation: Enter in the command window

x=[0:0.5:360]*pi/180;plot(x,sin(x),x,cos(x));

2.变量命名规则

2. Variable naming rules

1、变量赋值

1. Variable assignment

变量命名:以字母开头,后接字母、数字或下划线的字符序列,最多63个字符;变量名区分字母的大小写。

变量赋值:变量名=表达式

表达式 [自动赋值给变量ANS]

举例:在命令窗口输入

x=1+2i,y=3-sqrt(17)

z=(cos(abs(x+y))-sin(78*pi/180))/(x+abs(y))

Variable naming: start with a letter, followed by a sequence of letters, numbers or underscores, up to 63 characters; variable names are case sensitive

Variable assignment: variable name = expression

Expression [automatically assigned to variable ANS]

Example: Enter in the command window

x=1+2i,y=3-sqrt(17)

z=(cos(abs(x+y))-sin(78*pi/180))/(x+abs(y))

3.矩阵操作(Matrix operation)

1)矩阵的建立

直接输入法:将矩阵元素用方括号括起来,按矩阵行的顺序输入各元素,同一行各元素之间用空格或逗号分隔不同行的元素之间用分号分隔

2)利用冒号表达式建立一个行向量:e1:e2:e3

其中e1为初始值,e2为步长,e3为终止值;定义时可以不使用中括号、e2,默认步长为1。

1)The establishment of matrix

Direct input method: Enclose the matrix elements in square brackets, and enter the elements in the order of the matrix rows. The elements in the same row are separated by spaces or commas, and the elements in different rows are separated by semicolons.

2) Use the colon expression to create a row vector: e1:e2:e3

Among them, e1 is the initial value, e2 is the step size, and e3 is the end value; the brackets and e2 may not be used in the definition, and the default step size is 1.



3)用linspace函数产生行向量

linspace(a,b,n)。其中a和b是生成向量的第一个和最后一个元素,n是元素总数。linspace(a,b,n)与a:(b-a)/(n-1):b等价。具体操作如下图所示:

Use the linspace function to generate a row vector: linspace(a,b,n). Where a and b are the first and last elements of the generated vector, and n is the total number of elements. linspace(a,b,n) is equivalent to a:(b-a)/(n-1):b.The specific operation is shown in the figure below:



4)特殊矩阵 Special matrix

空矩阵[ ]:不包含任何元素,阶数为0×0。

产生特殊矩阵的函数:zeros(m,n)[产生零矩阵]。

Empty matrix [ ]: does not contain any elements, and the order is 0×0.

A function to generate a special matrix: zeros(m,n) [generate a zero matrix].

ones[产生全1矩阵]、eye[产生单位矩阵]

ones[generate all 1 matrix], eye[generate identity matrix]


rand[产生0~1间均匀分布的随机矩阵]、randn[产生均值为0,方差为1的标准正态分布随机矩阵]

rand[Generate a uniformly distributed random matrix between 0 and 1], randn[generate a standard normal distribution random matrix with a mean value of 0 and a variance of 1]


魔方矩阵:每行、每列及两条对角线上的元素和都相等;magic(n)生成一个n阶魔方阵。

具体操作如下图所示:

Magic cube matrix: the sum of the elements in each row, column and two diagonals are equal; magic(n) generates an n-order magic cube matrix.

The specific operation is shown in the figure below:

5.matlab之线性规划函数

Linprog( )对应的线性规划模型

min z=cx

Ax≤b

x≥0

[x,fval]=linprog(c,A,b,Aeq,beq,lb,ub)

其中,x返回线性规划的最优解(列向量)

fval返回目标函数最优值

c为目标函数系数(行/列向量)

A,b对应不等式约束A·x≤b

Aeq,beq对应等式约束Aeq·X=beq

lb,ub指定x的范围,即lb≤x≤ub,一般地,lb

为零向量,ub=[];b,beq,lb,ub均为列向量

举例:将下列模型转化为linprog格式

Min -z=-3x1-x2-4x3

sub.to 6x1+3x2+5x3≤45

3x1+4x2+5x3≤30

x1,x2,x3≥0

所以

c=[-3;-1;-4]; A=[6,3,5;3,4,5];

b=[45;30]; lb=zeros(3,1);

[x,fval]= linprog(c,A,b,[ ],[ ],lb,[ ])

计算机返回结果:x=(5;0;3),fval=-27

具体操作过程:

The linear programming model corresponding to Linprog( )

min z=cx

Ax≤b

x≥0

[x,fval]=linprog(c,A,b,Aeq,beq,lb,ub)

Among them, x returns the optimal solution of the linear programming (column vector).fval returns the optimal value of the objective function.c is the objective function coefficient (row/column vector).A, b corresponds to the inequality constraint A·x≤b.

Aeq, beq corresponds to the equality constraint Aeq·X=beq.lb,ub specifies the range of x, that is, lb≤x≤ub, generally, lb is a zero vector, ub=[ ]; b, beq, lb, ub are all column vectors

Example: Convert the following model to linprog format

Min -z=-3x1-x2-4x3

sub.to 6x1+3x2+5x3≤45

3x1+4x2+5x3≤30

x1, x2, x3≥0

so

c=[-3;-1;-4]; A=[6,3,5;3,4,5];

b=[45;30]; lb=zeros(3,1);

[x,fval]= linprog(c,A,b,[ ],[ ],lb,[ ])

The computer returns the result: x=(5;0;3), fval=-27

Specific operation process:


今天的分享就到这里了。

如果您对今天的文章有独特的想法,

欢迎给我们留言,

让我们相约明天,

祝您今天过得开心快乐!


That's it for today's sharing.

If you have a unique idea about today’s article,

Welcome to leave us a message,

Let us meet tomorrow,

I wish you a happy day today!


参考资料:电子工业出版社MATLAB教程第3版

英文翻译:Google翻译

本文由LearningYard学苑整理并发出,如有侵权请在后台留言!


LearningYard学苑

文案 | Qian

排版 | Qian

审核 | Tian

相关推荐

Excel技巧:SHEETSNA函数一键提取所有工作表名称批量生产目录

首先介绍一下此函数:SHEETSNAME函数用于获取工作表的名称,有三个可选参数。语法:=SHEETSNAME([参照区域],[结果方向],[工作表范围])(参照区域,可选。给出参照,只返回参照单元格...

Excel HOUR函数:“小时”提取器_excel+hour函数提取器怎么用

一、函数概述HOUR函数是Excel中用于提取时间值小时部分的日期时间函数,返回0(12:00AM)到23(11:00PM)之间的整数。该函数在时间数据分析、考勤统计、日程安排等场景中应用广泛。语...

Filter+Search信息管理不再难|多条件|模糊查找|Excel函数应用

原创版权所有介绍一个信息管理系统,要求可以实现:多条件、模糊查找,手动输入的内容能去空格。先看效果,如下图动画演示这样的一个效果要怎样实现呢?本文所用函数有Filter和Search。先用filter...

FILTER函数介绍及经典用法12:FILTER+切片器的应用

EXCEL函数技巧:FILTER经典用法12。FILTER+切片器制作筛选按钮。FILTER的函数的经典用法12是用FILTER的函数和切片器制作一个筛选按钮。像左边的原始数据,右边想要制作一...

office办公应用网站推荐_office办公软件大全

以下是针对Office办公应用(Word/Excel/PPT等)的免费学习网站推荐,涵盖官方教程、综合平台及垂直领域资源,适合不同学习需求:一、官方权威资源1.微软Office官方培训...

WPS/Excel职场办公最常用的60个函数大全(含卡片),效率翻倍!

办公最常用的60个函数大全:从入门到精通,效率翻倍!在职场中,WPS/Excel几乎是每个人都离不开的工具,而函数则是其灵魂。掌握常用的函数,不仅能大幅提升工作效率,还能让你在数据处理、报表分析、自动...

收藏|查找神器Xlookup全集|一篇就够|Excel函数|图解教程

原创版权所有全程图解,方便阅读,内容比较多,请先收藏!Xlookup是Vlookup的升级函数,解决了Vlookup的所有缺点,可以完全取代Vlookup,学完本文后你将可以应对所有的查找难题,内容...

批量查询快递总耗时?用Excel这个公式,自动计算揽收到签收天数

批量查询快递总耗时?用Excel这个公式,自动计算揽收到签收天数在电商运营、物流对账等工作中,经常需要统计快递“揽收到签收”的耗时——比如判断某快递公司是否符合“3天内送达”的服务承...

Excel函数公式教程(490个实例详解)

Excel函数公式教程(490个实例详解)管理层的财务人员为什么那么厉害?就是因为他们精通excel技能!财务人员在日常工作中,经常会用到Excel财务函数公式,比如财务报表分析、工资核算、库存管理等...

Excel(WPS表格)Tocol函数应用技巧案例解读,建议收藏备用!

工作中,经常需要从多个单元格区域中提取唯一值,如体育赛事报名信息中提取唯一的参赛者信息等,此时如果复制粘贴然后去重,效率就会很低。如果能合理利用Tocol函数,将会极大地提高工作效率。一、功能及语法结...

Excel中的SCAN函数公式,把计算过程理清,你就会了

Excel新版本里面,除了出现非常好用的xlookup,Filter公式之外,还更新一批自定义函数,可以像写代码一样写公式其中SCAN函数公式,也非常强大,它是一个循环函数,今天来了解这个函数公式的计...

Excel(WPS表格)中多列去重就用Tocol+Unique组合函数,简单高效

在数据的分析和处理中,“去重”一直是绕不开的话题,如果单列去重,可以使用Unique函数完成,如果多列去重,如下图:从数据信息中可以看到,每位参赛者参加了多项运动,如果想知道去重后的参赛者有多少人,该...

Excel(WPS表格)函数Groupby,聚合统计,快速提高效率!

在前期的内容中,我们讲了很多的统计函数,如Sum系列、Average系列、Count系列、Rank系列等等……但如果用一个函数实现类似数据透视表的功能,就必须用Groupby函数,按指定字段进行聚合汇...

Excel新版本,IFS函数公式,太强大了!

我们举一个工作实例,现在需要计算业务员的奖励数据,右边是公司的奖励标准:在新版本的函数公式出来之前,我们需要使用IF函数公式来解决1、IF函数公式IF函数公式由三个参数组成,IF(判断条件,对的时候返...

Excel不用函数公式数据透视表,1秒完成多列项目汇总统计

如何将这里的多组数据进行汇总统计?每组数据当中一列是不同菜品,另一列就是该菜品的销售数量。如何进行汇总统计得到所有的菜品销售数量的求和、技术、平均、最大、最小值等数据?不用函数公式和数据透视表,一秒就...