您当前的位置:首页 > 精选问答 > 内容

matlabsum函数用法,函数sum的用法简介(学会matlab,就多了一个科研小助手)

关于【matlabsum函数用法】,函数sum的用法简介,今天犇涌小编给您分享一下,如果对您有所帮助别忘了关注本站哦。

内容导航:1、matlabsum函数用法:MATLAB 函数sum的用法简介2、学会matlab,就多了一个科研小助手

1、matlabsum函数用法:MATLAB 函数sum的用法简介

Matlab的sum函数可以对一维向量甚至多维向量进行求和运算,下面小编就给大家分享一下如何使用。

操作方法

首先打开Matlab编辑软件,如下图所示,在软件中我们创建一个一维的向量

接下来直接调用sum函数将创建的向量传入进来,我们看到值立马计算出来了,如下图所示

接下来我们创建一个三维的向量,如下图所示,注意每一维度用分号隔开

然后又同样的将三维向量传入sum函数中,sum函数会自动为我们计算值,如下图所示

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

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

matlabsum函数用法,函数sum的用法简介(学会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.

matlabsum函数用法,函数sum的用法简介(学会matlab,就多了一个科研小助手)

#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))

matlabsum函数用法,函数sum的用法简介(学会matlab,就多了一个科研小助手)

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.

matlabsum函数用法,函数sum的用法简介(学会matlab,就多了一个科研小助手)

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:

matlabsum函数用法,函数sum的用法简介(学会matlab,就多了一个科研小助手)

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].

matlabsum函数用法,函数sum的用法简介(学会matlab,就多了一个科研小助手)

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

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

matlabsum函数用法,函数sum的用法简介(学会matlab,就多了一个科研小助手)

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]

matlabsum函数用法,函数sum的用法简介(学会matlab,就多了一个科研小助手)

魔方矩阵:每行、每列及两条对角线上的元素和都相等;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:

matlabsum函数用法,函数sum的用法简介(学会matlab,就多了一个科研小助手)

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:

matlabsum函数用法,函数sum的用法简介(学会matlab,就多了一个科研小助手)

今天的分享就到这里了。

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

欢迎给我们留言,

让我们相约明天,

祝您今天过得开心快乐!

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

本文关键词:matlab怎么读,matlab用的什么语言,matlab安装教程,matlab软件,matlab和python的区别。这就是关于《matlabsum函数用法,函数sum的用法简介(学会matlab,就多了一个科研小助手)》的所有内容,希望对您能有所帮助!


声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,谢谢。

上一篇: 适合20岁用的护肤品,揭秘适合20岁用的护肤品(20岁护肤品分享 巨好用)

下一篇: 教师资格证怎么考,教师资格证怎么看电子版(山东发布2023中小学教师资格考试报考须知)



推荐阅读

网站内容来自网络,如有侵权请联系我们,立即删除! | 软文发布 | 粤ICP备2021106084号