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

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

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


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

相关推荐

触乐怪话:存在于这个世界_触乐怪话存在于这个世界中吗

触乐怪话,每天胡侃和游戏有关的屁事、鬼事、新鲜事。太有意境了(图/小罗)童年时,人多的环境总让我感到压抑,幼儿园的时光大多在请假中度过。在家里,我的避世天地由两种爱好构成:家人电脑里的《帝国时代2》,...

表格是职场必备神器! 零基础也能快速上手——第7期

第七期:给学生分班。这一期会涉及几个函数公式,不要害怕,一点点的深入学习。我们不需要死记硬背,收藏起来,用的时候直接复制。我们需要学习的是概念,知道函数的意思,遇到想要解决的问题,能知道这个效果可以实...

福彩3D胆码公式趣谈:数字游戏里的"规律"探索指南

彩票的魅力,在于它用一组简单的数字,承载了人们对"意外惊喜"的无限想象。对于福彩3D这类数字型彩票,许多爱好者常热衷于研究"胆码公式"——试图通过历史开奖数据推导可能的...

航旅纵横9.9元精准延误险被吐槽,消费者直呼像 “买彩票”

近期,航旅纵横推出了一款9.9元的“惊喜数字”精准延误险,引发不少消费者吐槽。该产品因理赔条件苛刻,被指误导消费者,甚至有消费者认为其“赔付概率几乎为零,类似竞猜游戏”。据悉,该保险产品每天随机设...

Excel如何批量将数据拆分为多个数字之和

今天跟大家分享一下Excel如何批量将数据拆分为多个数字之和1.如下图C列含有一些数值,现在我们想要将这列数值拆分为三个数值之和。2.首先我们选中C2:C10单元格区域3.然后点击下图选项(Excel...

Go中select用法_go语言中的select

什么是selectselect语句用于从多个发送/接收通道操作中进行选择。select语句将一直阻塞,直到其中一个发送/接收操作准备就绪。如果多个操作准备就绪,则随机选择其中一个。语法类似于swi...

VLOOUP和MATCH函数公式组合太强了,高手必会!

传统的函数公式,更注重函数组合使用,VLOOKUP和MATCH函数公式组合,在工作中,经常能解决各种复杂的难题1、VLOOKUP+MATCH,一次性匹配多个值例如,现在左边的数据源,我们需要一交性匹配...

如何将人名打乱,随机排序?#excel技巧

人名打乱,随机排序。如何在需要随机分组时把现有人名打乱并进行随机排序呢?首先,随机排序用到的是排序函数,即数组函数sosby,然后对其进行排序,将其选中即可。那排序的依据是什么呢?因为要随机排序,所...

Power Query 随机抽样的自定义函数编写

在Excel中我们有Rand函数、Randbetween函数,我们可以产生随机数,然后通过这个随机数,作为索引,提取一行或一列中某个位置的数据。可以配合CHOOSE,INDEX等函数来实现随机抽取数据...

吾爱大神写的 随机选人(课堂小工具)

使用方法1导入名单(一行一个,从EXCEL复制到记事本即可,或者按照上图图解保存)2点击随机选人按钮提示1按按钮后蓝色方框无文字显示,代表所有人已被抽过,继续点击将开始新的一轮2按F5可以重新...

Excel 选不了单元格?3个高频原因 + 对应解法,5 分钟恢复操作

在使用Excel处理数据时,突然遇到单元格无法选定的情况,往往会打乱工作节奏。这种故障并非随机出现,通常与工作表保护设置、格式冲突或功能模式有关。本文将拆解3个高频原因,每个原因都配套1分钟排查...

CHOOSE函数的4个典型用法_choose函数公式怎么用

CHOOSE函数可以根据给定的索引号,返回参数列表中的值,其语法为CHOOSE(index_num,value1,[value2]...)。CHOOSE函数经常和其他函数一起组合使用,起着增强其他函数...

破解 20以内退位减法难题,这6 个实用方法助力孩子轻松掌握!

对于一年级的小朋友来说,不进位加法和进位加法比较容易,但减法比较难,特别是退位减法。我投身一线教学工作已近二十载。在此,我将结合一年级学生在学习20以内退位减法时的常见困境,提出六条具有实用性的建...

C语言随机数生成_c语言随机数如何生成

C语言rand和srand用法详解,在C语言实际编程过程中经常要使用到随机函数。例如,贪吃蛇游戏中在随机的位置出现食物,扑克牌游戏中随机发牌。在C语言中,我们一般使用<stdlib.h>...

千禧年大奖难题BSD猜想进展:这些整数可以写成两个有理数立方和

选自quantamagazine作者:EricaKlarreich机器之心编译机器之心编辑部这项工作第一次明确了有多少整数可以写成两个分数的立方和今年早些时候,三位数学家讨论了数论中最古老的问题之一...