Ave ave Basics

Source: Internet
Author: User
Tags in degrees
Ave ave Basics

I. Introduction

What is 1.1 Ave ave?

Ave ave is an open-source software for numerical computation and plotting. Like MATLAB, Ave ave is especially useful in matrix operations: solving simultaneous equations, calculating matrix feature values and feature vectors.

1.2 Applicable objects of Ave ave

Octave and Matlab are widely used by engineering and scientific research personnel for various industrial and academic numerical calculations and simulations. For example, NASA uses it to develop an aircraft docking system, and jauar racing uses it to visualize and analyze data transmitted from F1 cars, and Sheffield uses it to develop software for identifying cancer cells. Software such as Ave ave makes it easy to write a numerical processing program and provides multiple ways of data visualization.

1.3 download and install Ave ave

Refer to relevant online tutorials;


2. Simple computing

2.1 The simplest way to use Ave ave is to enter the corresponding formula in the command prompt like using a calculator. Ave ave can recognize common computation expressions. For example, enter

Ave ave: ##> 2 + 2

And press enter, you will get the following result ans = 4

The priority of each calculated symbol is the same as that of a regular symbol. For example, the brackets have the highest priority, followed by the multiplication and division, and finally the addition and subtraction operations.

2.2 built-in functions

There are many built-in functions in Ave ave, which can be called by the input function name and the input parameters in brackets. For example:

Octave: ##> exp (1)

Ans = 2.71813

Another longer expression: Calculate 1.2 sin (40? + Ln (2.42), input octave: ##> 1.2 * sin (40 * PI/180 + Log (2.4 ^ 2 ))

Ans = 0.76618

The basic mathematical functions include sin, cos, tan, log, exp, Abs, floor, Ceil, etc;

To exit Ave ave, enter quit or exit at the command prompt.


3. octave variable

3.1 Variables

Variables can be defined like C ++ and Java, but Ave ave is an explanatory language. Therefore, the types of variables in Ave ave do not need to be declared, but the variable names in octave differentiate the sizes, that is, variables A and A are different variables.

Octeave: ##> deg = PI/180

DEG = 0.017453

 

If you need to delete a variable from the current variable space, the clear command can remove all the variables or a specific variable, such:

Clear name? Removes a variable named name.

3.2 load and save data

When you exit Ave ave, you will lose the variable you created. If you need to exit Ave ave halfway through work, you can save the data of the current session and re-Load it later. If you enter

Octave: ##> save anyname?

This stores the variables in the workspace to the next file named anyname. mat in the current directory (note. mat is automatically added by Ave ave ). In this way, you can exit Ave ave, restart the octave program, and enter

Octave: ##> loadanyname

It will reload the previously saved namespace and start working from where you are interrupted. Similarly, you can load or save specific variables. Format:

Octave: ##> save filename var1 var2...

For example, if you want to store the deg variable, you can enter

Octave: ##> save degconv deg?

In this way, the deg variable is stored in the file named degconv. Mat. You can re-load the variable by running the following command:

Octave: ##> loaddegconv

Ave ave can also import data from files. This feature is useful when you use other data sources for drawing or computing.

For example:

Xforwarload('featurex.txt ');

3.3 get help

If you do not know how to use a command or function, you can also use the help command to obtain its detailed usage.

Help commandname

Example: help plot

3.4 semicolon and hidden results

A semicolon is used in a common programming language to indicate the end of a program block or a single statement. In Ave ave, semicolons are not required, but they also have a special feature. In our current example, if we enter a Ave ave command that does not end with a semicolon, Octave will display the statement execution result immediately. However, if we add a semicolon to the end of a line of statements, Ave ave will not display the corresponding results.

Four arrays and vectors and Matrices

The advantage of Ave ave is that it can easily perform matrix-related computing.

4.1 Constructor

There are many methods to construct a matrix or vector. The most direct and simple method is to give its elements in a square brackets [], for example

Ave ave: ##> A = [1 4 5]

A = 1 4 5

Ave ave: ##> B = [2, 1, 0]

B = 2 1 0

Octave: ##> c = [4; 7; 10]

C = 4

7

10

A group of data separated by spaces or commas in square brackets is defined as a row vector, and a group of data separated by semicolons or carriage returns is defined as a column vector. You can use defined vectors to define new vectors, such

Ave ave: ##> A = [1 4 5]

A = 1 4 5

Octave: ##> d = [A 6]

D = 1 4 5 6

4.2 colon expression

Using colons can easily create some special Vectors

Octave: ##> E = 2: 6

E = 2 3 4 5 6

The rule for a colon expression is to tell Ave ave to create a vector that starts with the first number and increments to the second number. You can insert a third parameter between the first and second numbers to declare the increasing quantity of elements in the vector, such as A: B: C.

4.3 vector Constructor

Zeros (m, n) creates an all-zero matrix of mxn.

Ones (m, n) creates an mxn full matrix

Linspace (x1, x2, n) creates a vector of n elements evenly distributed in X1 and X2

Eye (m) creates an mxm unit matrix

Rand (m, n) creates an mxn matrix with random values.

4.4 element operations in a vector

Elements in a vector are enclosed in parentheses (), and the first element is numbered 1, rather than starting from 0 as C or C ++. For example

Ave ave: ##> A = [-1 0]

A = 1 3 5-1 0

We can use the following command to access the third element of the vector.

Octave: ##> A (3)

Ans = 5

The colon notation can also be used to declare the range of elements in a vector.

Octave: ##> A (3: 5)

Ans = 5-1 0

Octave: ##>)

Ans = 1 5 0

4.5 vector calculation

After a set of data is saved to a vector, many Ave ave functions can be used for computation. In C ++, if you want to perform the same calculation, for example, multiply each element by 2, you need to use the for loop to operate on each element. Although the for loop can also be used in the Ave ave, the octave itself has a simple vector operation method.

In a vector, each number can be multiplied by a number. Take the previously defined a vector as an example:

Ave ave: 1> A = [-1 0]

A =? 1 3 5-1 0

Ave ave: 2> A * 2

Ans = 2 6 10-2 0

The operation for dividing all elements in a vector by a number is similar to multiplication. Use +? Operator, you can also add or subtract a value to each element in the vector. The multiplication of two vectors follows the multiplication Law of the matrix. The multiplication of vectors is not the multiplication of corresponding elements. If you want to perform multiplication and division of corresponding elements, you can use. * And./operators to note that the '.' before each operator represents the calculation of an element pair element. For example:

Ave ave: 3> B =

B = 1 2 3 4 5

Ave ave: 4> A. * B

Ans = 1 6 15-4 0

The multiplication of elements one by one is also useful. The operator for this calculation is, for example

Ave ave: 5> B. ^ 2

Ans = 1 4 9 16 25

Octave: 6> 2. ^ B

Ans = 2 4 8 16 32

Ave ave: 7> A. ^ B

Ans =? 1 9 125 1 0

As long as the two vectors share the same size and shape, they can perform element-by-element addition, subtraction, division, and multiplication.

4.6 function operator Vector

The previously mentioned functions can also be applied to vectors.

Example: exp, log, Abs, etc.

Octave: ##> ABS ([-1 2-3])

Ans = 1 2 3

In addition, functions such as Max, length, size, sum, mean, STD, floor, And Ceil may need to be mastered. You can use the help command to obtain detailed usage.

4.7 transpose of the matrix

A vector is converted from a row vector to a column vector or from a column vector to a row vector. Transpose the Matrix to swap its rows and columns. In mathematics, the transpose expression of matrix A is as follows:

Ave ave: 6> A = [5 7 9;-1 3-2]

A = 5 7 9

-1 3-2

Ave ave: 7>'

Ans = 5-1

7 3

9-2

In addition, inv calculates the inverse of the matrix, det calculates the matrix feature value, and trace calculates the trace of the matrix.

5. Drawing

Octave calls another open-source software, gnuplot, to implement a rich set of drawing functions. The most basic drawing command is plot (x, y), where X and Y are horizontal and vertical data respectively. You can select the appropriate color and style, for example, 'ro' represents the Red Circle, 'B. 'indicates a blue dot. You can use title, xlabel, and ylabel to add the title and X and Y axis names. The legend command adds a legend for the image.

5.1 if you want to save the current image content and stack the newly created image to the original image, you can use the hold on command. With this command, we can display the lines drawn by the two plot commands on the same image.

Octave: ##> x = linspace (-10, 10 );

Ave ave: ##> plot (x, sin (x), 'r -');

Octave: ##> hold on

Ave ave: ##> plot (x, sin (x)./X, 'B *')

Ave ave: ##> title ('figure ')

Octave: ##> xlabel ('x ')

Octave: ##> ylabel ('y ')

Ave ave: ##> legend ('sin (x) ', 'sin (X)/X ')


5.2 subplot (, 2) indicates drawing in a grid. Therefore, this statement is divided into 2x3 grids and drawn in 2nd grids. The subgrids are sequentially ascending from left to right, from top to bottom, that is

1 2

3 4

5 6

For example:

Octave: ##> x = linspace (-10, 10 );

Octave: ##> subplot (2, 1, 1)

Octave: ##> plot (x, sin (x ));

Octave: ##> subplot (2, 1, 2)

Octave: ##> plot (x, sin (x)./X)


More than 5.3 images can be implemented using the figure command.

5.4 draw a surface

Ave ave: ##> x =;

Octave: ##> y =;

Octave: ##> [x, y] = meshgrid (x, y); % make the grid

Octave: #> Z = (X-3). ^ 2-(Y-2). ^ 2;

Octave: ##> subplot (2, 2, 1); SURF (z); Title ('surf ')

Octave: ##> subplot (2, 2); mesh (z); Title ('mesh ')

Octave: ##> subplot (2, 2, 3); meshz (z); Title ('meshz ')

Octave: ##> subplot (2, 2, 4); contour (z); Title ('contour ')



Ave ave script

If you have some repeated commands, you can save these commands into a octave script. This text file containing the Ave ave command is the basic form of the octave program. When you execute such a script in Ave ave, the effect is the same as that of inputting one line of these commands into Ave ave. And when you are not very accurate about a series of commands to input Ave ave, modifying these commands in a script is much simpler and easier than calling and modifying commands in the Ave ave terminal.

The octave script is a common text file, but they need a. m suffix (e. g. Run. m ). Therefore, they are also known as M files. The file name excluding the suffix is the part you need to input to the Ave ave terminal when executing this command.

You can create and edit a script file in any text editor (such as Emacs, Vi, notepad. In Ave ave, run the following command:

Octave: ##> Edit

Call up the text editor Emacs in a new window. If you want to edit an existing script, you can add the script name after the edit command. For example, if you have a script named run. M, entering edit run will bring up the editor and open the file for editing.

Then enter run in Ave ave to execute the script:

Octave: ##> run

Ave ave will run the commands in the script and get the corresponding results.

Seven control statements

The programs or expressions we have seen so far are simple operations executed in sequence. The use of vectors and matrices allows Ave ave to perform more advanced calculations. However, to implement more complex functions, we still need some standard programming languages. Ave ave provides common loops and selection statements. Its syntax is similar to the well-known C, C ++, Java and other programming languages.

Here is just an example:

Octave: ##> x = 1;

Ave ave: ##> while 1 + x> 1

X = X/2;

End

Octave: ##> x

X =

1.1102e-16

Octoave Function

Scripts in Ave ave can implement some simple programs, but user-defined functions are more powerful than scripts. Custom functions allow you to call them in command lines, other functions, and scripts.

In the Ave ave function, parameters are passed through values instead of reference and multiple return values can be returned. Like a script, the Ave ave function is written into a plain text file. The difference is that the first line of the function File follows the following format:

Function [output1, output2,...] = Name (input1, input2 ,...)

Each function is uninstalled from a different M file, and the M file name must not be the same as the function name. For example, a function named sind () must be defined in the M file named sind. M. Each function receives a certain number of input parameters and outputs a certain number.

When you need to execute a certain expression repeatedly, it indicates that you need to encapsulate the operation as a function. After being encapsulated as a function, Ave ave is easier to use and increases the readability of the code and can be used by others.

We can create such a function to create a text file named sind. m that contains the following content:

Function S = sind (X)

% Sind (x) calculates sine (x) in degrees

S = sin (x * PI/180 );

End

Then you can use this function, for example:

Octave: ##> sind (0)

Ans = 0

Octave: ##> sind (45)

Ans = 0.7071

Octave: ##> T = sind ([30 60 90])

T = 0.50000.8660 1.0000

 


Ave ave Basics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.