Octave基本文法

來源:互聯網
上載者:User

標籤:sprintf   1.7   hid   語句   mat   ||   print   pre   sqrt   

基本運算

octave:3> 5+6ans =  11octave:4> 3-2ans =  1octave:5> 8*9ans =  72octave:6> 8/4ans =  2octave:7> 6/4ans =  1.5000octave:8> 2^6ans =  64octave:9>

 

注釋:% 表示注釋符號

octave:9> 1 == 2 %false
ans = 0
octave:10> 1~=2
ans = 1
octave:11> 1 && 0 % AND
ans = 0
octave:12> 1 || 0 % OR
ans = 1
octave:13> xor(1,0) % 異或
ans = 1
octave:14>

 改變提示符: octave:14> PS1(‘>> ‘); ,‘ ‘ 內表示所選提示符

 

>> a=3a =  3>> a=3;%加上分號將不會顯示>> aa =  3>> a=3;>> a=2a =  2>> a=2;%加上分號將不會顯示
>> b=‘hi‘
b = hi
>> c=(3>=1)
c = 1
>> a=pi
a = 3.1416
>> disp(a)
3.1416
>> disp(sprintf(‘2 decimals: %0.2f‘,a)) % 類似於C語言的輸出語句
2 decimals: 3.14

 

 

矩陣和向量

>> A = [1 2; 3 4; 5 6]A =   1   2   3   4   5   6>> A=[1 2;3 4;5 6]A =   1   2   3   4   5   6>> V=[1 2 3]V =   1   2   3>> V=[1;2;3]V =   1   2   3>> V=1:0.1:2V = 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:6V =   1   2   3   4   5   6>> ones(2,3)ans =   1   1   1   1   1   1>> 2*ones(2,3)ans =   2   2   2   2   2   2>> C=[2 2 2;2 2 2]C =   2   2   2   2   2   2>> w=ones(1,3)w =   1   1   1>> w=zeros(1,3)w =   0   0   0>> w=rand(1,3)w =   0.76244   0.97843   0.82005>> w=rand(3,3) %產生隨機數矩陣,範圍0~1w =   0.844846   0.070033   0.276175   0.330128   0.777480   0.369802   0.015571   0.482700   0.163547>> w = randn(1,3) %產生服從高斯分量的隨機矩陣w =   0.63218   0.16167  -0.34970>>
View Code

 

 繪製長條圖:

>> w=-6 + sqrt(10)*(randn(1,10000));>> hist(w)

 

繪製更多豎條的長條圖(50個):

>> hist(w,50)

 

 

單位矩陣:

>> i=eye(4)i =Diagonal Matrix   1   0   0   0   0   1   0   0   0   0   1   0   0   0   0   1

 

可輸入help命令獲得協助,如:

help eye 

help rand

 

Octave基本文法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.