Octave Primer (1)

Source: Internet
Author: User

1) Modify prompt string: PS1('>>')  

>>ps1 ('input:') Input:12

2) operation

>> 1+2
Ans=3>>1*2ans=2>>1 == 2ans=0>>1 != 2ans=1>>1 && 0ans=0>>1 || 0ans=1

3) output: disp; Formatted output with disp (sprintf (...)); Format is used to specify the length of the DISP output variable

>> A ==  3.1416>> disp3.1416disp(sprintf( ' 2 decimals:%0.2f ' , a)) 2 3.14

>> Format Long
>> A
A = 3.14159265358979

4) Matrix

>> A = [1 2;3 4;5 6]% definition matrix AA=1   2   3   4   5   6>> A = [1 2; % Definition matrix A>3 4;>5 6]a=1   2   3   4   5   6

5) Vector

>> v = [123=   1   2   3>> v = [ 1 2 3  =   1   2   3

>> v = 1:0.1:2% definition vector, starting at 1, ending at 2, each vector element incrementing by 0.1
v =

Columns 1 through 7:

1.0000 1.1000 1.2000 1.3000 1.4000 1.5000 1.6000

Columns 8 through 11:

1.7000 1.8000 1.9000 2.0000

>> v = 1:6% definition vector, starting at 1, ending with 6, incrementing each vector by 1
v =

1 2 3 4 5 6

6) Ones/zeros: Defines a matrix with all 1/0 elements

 >> ones (2 , 3  )% Definition 2 * 3 matrix, each element is 1ans  = 1  1<   /span> 1  1  1  1  >> C = 3  * Ones (2 , 3  ) C  = 3  3  3  3  3 
>> B = Zeros (1,3=   0   0   0>> B = zeros ( 3  =   0   0   0   0    0   0   0   0   0

7) Rand/randn: Defines the matrix where the element is a random number, where Rand is evenly distributed and RANDN is normally distributed

 >> rand (3  ) ans  = 0.77517  0.50079  0.63386  0.23687  0.89551  0.65577  0.29754  0.54136  0.68766  > > rand (2 , 3  ) ans  = 0.38275  0.67953  0.12146  0.15065  0.93036  0.95690  
 >> randn (3  ) ans  = 0.439525  1.104126 -0.725249  Span style= "color: #800080;" >0.073562  0.505057 -0.398156  Span style= "color: #800080;" >0.341471  0.719360  0.629861  > > Randn (2 , 3  ) ans  =-0.28960 -1.18585 -0.62750 -0.58217 -< Span style= "color: #800080;" >1.48229  0.25587  

8) hist (histogram) display histogram

9) Eye: Produces an n-order unit matrix

octave-3.6.4Exe One> Eye (5) ans=Diagonal Matrix1   0   0   0   0   0   1   0   0   0   0   0   1   0   0   0   0   0   1   0   0   0   0   0   1

Octave Primer (1)

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.