diary on
x=5
x =
5
a=[4;7;9]
a =
4
7
9
a=[4,7,9]
a =
4 7 9
a=[4,7,9]'
a =
4
7
9
A=[5,7,3;1,4,2]
A =
5 7 3
1 4 2
size A
ans =
1 1
size(A)
ans =
2 3
A*a
ans =
96
50
A
A =
5 7 3
1 4 2
a
a =
4
7
9
b=[1 2 3]'
b =
1
2
3
a.*b
ans =
4
14
27
a.^2
ans =
16
49
81
a*b'
ans =
4 8 12
7 14 21
9 18 27
a(2)
ans =
7
A(2,1)
ans =
1
A
A =
5 7 3
1 4 2
A(2,:)
ans =
1 4 2
t=0:1:5
t =
0 1 2 3 4 5
t
t =
0 1 2 3 4 5
x=0:0.01:2*pi;
size(x)
ans =
1 629
y=sin(x);
size(y)
ans =
1 629
plot(x,y,'r')
x=rand(1)
x =
0.9501
x=rand(1)
x =
0.2311
x=rand(1)
x =
0.6068
x=rand(1)
x =
0.4860
help rand
RAND Uniformly distributed random numbers.
RAND(N) is an N-by-N matrix with random entries, chosen from
a uniform distribution on the interval (0.0,1.0).
RAND(M,N) and RAND([M,N]) are M-by-N matrices with random entries.
RAND(M,N,P,...) or RAND([M,N,P,...]) generate random arrays.
RAND with no arguments is a scalar whose value changes each time it
is referenced. RAND(SIZE(A)) is the same size as A.
RAND produces pseudo-random numbers. The sequence of numbers
generated is determined by the state of the generator. Since MATLAB
resets the state at start-up, the sequence of numbers generated will
be the same unless the state is changed.
S = RAND('state') is a 35-element vector containing the current state
of the uniform generator. RAND('state',S) resets the state to S.
RAND('state',0) resets the generator to its initial state.
RAND('state',J), for integer J, resets the generator to its J-th state.
RAND('state',sum(100*clock)) resets it to a different state each time.
This generator can generate all the floating point numbers in the
closed interval [2^(-53), 1-2^(-53)]. Theoretically, it can generate
over 2^1492 values before repeating itself.
MATLAB Version 4.x used random number generators with a single seed.
RAND('seed',0) and RAND('seed',J) cause the MATLAB 4 generator to be used.
RAND('seed') returns the current seed of the MATLAB 4 uniform generator.
RAND('state',J) and RAND('state',S) cause the MATLAB 5 generator to be used.
See also randn, sprand, sprandn, randperm.
Reference page in Help browser
doc rand
RAND('state',sum(100*clock))
??? Undefined command/function 'RAND'.
rand('state',sum(100*clock))
N=100
N =
100
rand('state',0)
x=rand(1)
x =
0.9501
rand('state',sum(100*clock))
u=rand(N,1)
u =
0.3250
0.9595
0.5752
0.6019
0.0368
0.0535
0.7024
0.1529
0.2807
0.0190
0.0913
0.1062
0.2731
0.8910
0.8698
0.4291
0.0011
0.0851
0.8930
0.2801
0.7188
0.2144
0.6345
0.8828
0.1944
0.6847
0.9401
0.8732
0.0652
0.4065
0.1675
0.2269
0.9032
0.5564
0.9745
0.3697
0.1898
0.6875
0.2666
0.4922
0.6408
0.7112
0.7089
0.1435
0.2797
0.6847
0.4707
0.6151
0.0335
0.8417
0.6013
0.1376
0.5921
0.0659
0.0261
0.2089
0.0372
0.5595
0.2472
0.1864
0.9742
0.0905
0.0650
0.8781
0.0207
0.8663
0.7499
0.5524
0.4918
0.8430
0.5247
0.6971
0.5345
0.5861
0.1417
0.7805
0.4370
0.0494
0.4809
0.9186
0.3103
0.5612
0.6379
0.8677
0.0791
0.7735
0.0028
0.2895
0.1415
0.6640
0.4791
0.6084
0.8112
0.0836
0.1360
0.4025
0.4342
0.9787
0.3784
0.6737
u=(1:10)
u =
1 2 3 4 5 6 7 8 9 10
u=rand(N,1);
u=1:10
u =
1 2 3 4 5 6 7 8 9 10
u=rand(N,1);
u1:10
??? Undefined function or variable 'u1'.
u(1:10)
ans =
0.1833
0.2888
0.3446
0.5622
0.6186
0.2811
0.8350
0.6241
0.4263
0.8080
fa = hist(u,10)
fa =
13 8 11 8 13 10 10 7 8 12
f=fa/N
f =
Columns 1 through 7
0.1300 0.0800 0.1100 0.0800 0.1300 0.1000 0.1000
Columns 8 through 10
0.0700 0.0800 0.1200
delta=0.1
delta =
0.1000
h=f/delta
h =
Columns 1 through 7
1.3000 0.8000 1.1000 0.8000 1.3000 1.0000 1.0000
Columns 8 through 10
0.7000 0.8000 1.2000
bar(h)
uc=0.05:0.1:0.95
uc =
Columns 1 through 7
0.0500 0.1500 0.2500 0.3500 0.4500 0.5500 0.6500
Columns 8 through 10
0.7500 0.8500 0.9500
bar(uc,h)
N=1000
N =
1000
u=rand(N,1);
fa = hist(u,10)
fa =
102 107 117 81 104 103 92 91 116 87
f=fa/N
f =
Columns 1 through 7
0.1020 0.1070 0.1170 0.0810 0.1040 0.1030 0.0920
Columns 8 through 10
0.0910 0.1160 0.0870
h=f/delta
h =
Columns 1 through 7
1.0200 1.0700 1.1700 0.8100 1.0400 1.0300 0.9200
Columns 8 through 10
0.9100 1.1600 0.8700
bar(uc,h)
figure
bar(uc,h,1)
figure
bar(uc,h,1)
N=100000
N =
100000
u=rand(N,1);
fa = hist(u,10)
fa =
Columns 1 through 6
10116 9923 10154 10220 9812 9885
Columns 7 through 10
10073 9965 9889 9963
f=fa/N
f =
Columns 1 through 7
0.1012 0.0992 0.1015 0.1022 0.0981 0.0988 0.1007
Columns 8 through 10
0.0997 0.0989 0.0996
h=f/delta
h =
Columns 1 through 7
1.0116 0.9923 1.0154 1.0220 0.9812 0.9885 1.0073
Columns 8 through 10
0.9965 0.9889 0.9963
figure
bar(uc,h,1)
N=5
N =
5
N=10
N =
10
M=10000
M =
10000
u=rand(N,M);
size(u)
ans =
10 10000
%Ho ripetuto 10000 volte le 10 estrazioni
%Devo fare la media per colonne
m=mean(u,1);
size(m)
ans =
1 10000
%Media = mean
close all
hist(m,50)
1/12
ans =
0.0833
(1/12)/10
ans =
0.0083
sqrt((1/12)/10)
ans =
0.0913
%Media dell'uniforme é 0.5, la varianza é 1/12
N=100
N =
100
u=rand(N,M);
figure
m=mean(u,1);
hist(m,50)
N=10000
N =
10000
u=rand(N,M);
N=100
N =
100
u=rand(N,M);
m=mean(u,1);
hist(m,50)
s2=var(u,1);
figure
hist(s2,50)
1/12
ans =
0.0833
mean(s2)
ans =
0.0823
N=10
N =
10
u=rand(N,M);
m=mean(u,1);
hist(s2,50)
N=5
N =
5
u=rand(N,M);
s2=var(u,1);
figure
hist(s2,50)
mean(s2)*5/4
ans =
0.0836
mean(s2)
ans =
0.0668
clear alla
clear all
clc
clear
clc
x=1,1
x =
1
ans =
1
x=[1;1]
x =
1
1
t=(0:1:4)'
t =
0
1
2
3
4
A = [t ones (5,1)]
??? A = [t ones (5,1)]
|
Error: Incomplete or misformed expression or statement.
A = [t ones(5,1)]
A =
0 1
1 1
2 1
3 1
4 1
y=A*x
y =
1
2
3
4
5
figure
plot(x,y)
??? Error using ==> plot
Vectors must be the same lengths.
plot(t,y)
plot(t,y,'-o')
%Supponiamo che siano medie di VC ai diversi tempi
v=randn(5,1)
v =
-0.4326
-1.6656
0.1253
0.2877
-1.1465
Y0=y+v
Y0 =
0.5674
0.3344
3.1253
4.2877
3.8535
hold on
plot(t,Y0,'or')
plot(t,y,'-o')
plot(t,Y0,'or')
hold on
plot(t,y,'-o')
grid on
%Ho sommato alla retta le estrazioni da una NORMALE
N=A'*A
N =
30 10
10 5
Tn=A'*Y0
Tn =
34.8622
12.1684
xst = N^(-1)*tn
??? Undefined function or variable 'tn'.
xst = N^(-1)*Tn
xst =
1.0525
0.3286
yst=A*xst;
hold on
plot(t,yst,'o-g')
vst=Y0-yst
vst =
0.2388
-1.0467
0.6917
0.8015
-0.6852
sigma02st=(vst' * vst)/(5-2)
sigma02st =
0.9143
Cxxst=sigma02st*N^(-1)
Cxxst =
0.0914 -0.1829
-0.1829 0.5486
N^(-1)
ans =
0.1000 -0.2000
-0.2000 0.6000
diary off