Quick Matlab knowledge required for mathematical modeling

Recently, I was preparing for mathematical modeling, so I came to the special topic to learn matlab. I will treat it here as my learning record. I hope it can help everyone.

for the purpose

arctanx is represented as atan() in matlab, for example: >> atan(1)-pi/4 % means arctan(1)-π/4ans = 0

Comment

Single line comments

For single-line comments, use: %, as shown below:

%绘制正弦曲线
clear;
close all;
clc;
x=-2*pi:0.01:2*pi;
y=sin(x);
plot(x,y)

Multi-line comments

For multi-line comments, it is appropriate to use: %{ %} (of course you can also use % to comment), as shown below:

%{
把图形显示窗口分成四个格子,
每个格中显示不同的正弦曲线。
%}
clear;
close all;
clc;
x=-2*pi:0.01:2*pi;
y1=sin(x);
y2=sin(2 .* x);
y3=sin(3 .* x);
y4=sin(4 .* x);

subplot(2,2,1);
plot(x,y1)

subplot(2,2,2);
plot(x,y2)

subplot(2,2,3);
plot(x,y3)

subplot(2,2,4);
plot(x,y4)

shortcut key

  1. Ctrl+R can realize % comment (you can comment even if you select multiple lines);
  2. Ctrl+T, cancel the % comment (multiple lines are also ok);

meshgrid

2D and 3D meshes

grammar

[X,Y] = meshgrid(x,y)
[X,Y] = meshgrid(x)
[X,Y,Z] = meshgrid(x,y,z)
[X,Y,Z] = meshgrid(x)

illustrate

Example

[X,Y] = meshgrid(x,y)Returns 2D grid coordinates based on the coordinates contained in vectors xand . is a matrix, each row is a copy of ; is also a matrix, each column is a copy of . The coordinates and represent a grid with rows and columns.yXxYyXYlength(y)length(x)

Example

[X,Y] = meshgrid(x)Same as [X,Y] = meshgrid(x,x)and returns the coordinates of a square grid with grid size length(x)× length(x).

Example

[X,Y,Z] = meshgrid(x,y,z)Returns the 3D grid coordinates defined by the vectors x, yand . The size of the grid represented by , and is × × .zXYZlength(y)length(x)length(z)

Example

[X,Y,Z] = meshgrid(x)Same as [X,Y,Z] = meshgrid(x,x,x)and returns the three-dimensional grid coordinates with grid size length(x)× length(x)× length(x).

Let’s first take a look at the interface structure of Matlab:

At the far left of the interface is the file directory, in the middle is the command line window, and on the right is the workspace

This blog is mainly for mathematical modeling. Of course, you can also refer to it if you need a quick test before the exam.

1. Generate matrix
First let’s look at the way to generate matrix:

1. Direct method

code show as below:

matrix = [1, 2, 3; 4, 5, 6; 7, 8, 9]

Enter the above code in the command line window to get the generated matrix.

The above are some of my notes, but the above is not the focus!
It’s below! I recommend everyone to study this blog. The blogger has organized it very well.

Quickly learn the Matlab knowledge required for mathematical modeling, two hours of Matlab quick learning, Matlab tutorial for beginners
https://blog.csdn.net/a1351937368/article/details/105848991

If you offend the blogger above, please contact me to delete the post. Thank you. Come on everyone.

Guess you like

Origin blog.csdn.net/smile66688/article/details/119685993