下载地址:https://www.gnu.org/software/octave/download.html#ms-windows 选择windows exe 下载后选择合适的安装路径即可。
基本操作:
>> 5+6
ans = 11
>> 3-2
ans = 1
>> 5*8
ans = 40
>> 1/2
ans = 0.5000
>> 1==2
ans = 0
>> 1~=2
ans = 1
>> 1&&2
ans = 1
>> 1&&0
ans = 0
>> 1||0
ans = 1
>> 1==2 %false
ans = 0
>> xor(1,0)
ans = 1
>> a=3
a = 3
>> a=3;
>> b='hi';
>> c=~(3>=1)
c = 0
>> c=(3>=1)
c = 1
>> a=pi;
>> a
a = 3.1416
>> disp(a);
3.1416
>> disp(sprintf('2 decimals:%0.2f',a))
2 decimals:3.14
>> disp(sprintf('6 decimals:%0.6f',a))
6 decimals:3.141593
>> format long
>> a
a = 3.141592653589793
>> format short
>> a
a = 3.1416
>> 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:2
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:2
v =
1 2
>> v=1:6
v =
1 2 3 4 5 6
>> ones(2,3)
ans =
1 1 1
1 1 1
>> c=2*ones(2,3)
c =
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.5885 0.4039 0.7867
>> w=rand(1,3)
w =
0.656347 0.926736 0.057125
>> w=rand(1,3)
w =
0.2671 0.5931 0.8374
>> w=randn(1,3)
w =
-0.7486 -0.2935 0.5563
>> w=-6+sqrt(10)*(randn(1,10))
w =
Columns 1 through 7:
-1.5782 -5.2167 -4.2591 -3.7272 -9.6826 -6.8219 -13.5319
Columns 8 through 10:
-7.9996 -5.3716 -3.9066
>> w=-6+sqrt(10)*(randn(1,10))
w =
Columns 1 through 7:
-4.1697 -8.6158 -10.1010 -9.0397 -10.0128 -10.9708 -6.3892
Columns 8 through 10:
-4.2694 -4.8263 1.8562
>> w=sqrt(10)
w = 3.1623
>> w=sqrt(16)
w = 4
>> eye(4)
ans =
Diagonal Matrix
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
>> i=eye(4)
i =
Diagonal Matrix
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
>> I=eye(6)
I =
Diagonal Matrix
1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1
>> A=[1,2,3;4,5,6]
A =
1 2 3
4 5 6
>> A=[1,2,3;4,5,6;7,8,9]
A =
1 2 3
4 5 6
7 8 9