This presentation is the property of its rightful owner.
Sponsored Links
1 / 40

标准方差与相关系数 1 .求标准方差 PowerPoint PPT Presentation


  • 161 Views
  • Uploaded on
  • Presentation posted in: General

标准方差与相关系数 1 .求标准方差 在 MATLAB 中,提供了计算数据序列的标准方差的函数 std 。对于向量 X , std(X) 返回一个标准方差。对于矩阵 A , std(A) 返回一个行向量,它的各个元素便是矩阵 A 各列或各行的标准方差。 std 函数的一般调用格式为: Y=std(A,flag,dim)

Download Presentation

标准方差与相关系数 1 .求标准方差

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


1

1

MATLABstdXstd(X)Astd(A)Astd

Y=std(A,flag,dim)

dim12dim=1dim=2flag01flag=01flag=12flag=0dim=1

6-7 x


1

2

MATLABcorrcoefcorrcoef

corrcoef(X)XXX

corrcoef(X,Y)X,Ycorrcoef([X,Y])


1

1000055

X=randn(10000,5);

M=mean(X)

D=std(X)

R=corrcoef(X)


1

MATLABXsort(X)X

sortA

[Y,I]=sort(A,dim)

dimAdim=1dim=2YIYA


1

x=lp(C,A,b,vlb,vub)


1

%First, enter the coefficients:

f = [-5; -4; -6] ;

A = [1 -1 1

3 2 4

3 2 0];

b = [20; 42; 30];

lb = [0,0,0]; % x [0,0,0]

ub = [inf,inf,inf];

%Next, call a linear programming routine:

x= lp(f,A,b,lb,ub)

%Entering x

x =

0.0000

15.0000

3.0000

[]

f(x)=-5x1-4x2-6x3

x1-x2+x320

3x1+2x2+4x342

3x1+2x230

(0x1, 0x2,0x3)


1

[]

Min -400x1-1000x2-300x3+200x4

-2x2 + x3 + x4=0

2x1 +3x2 <=16

3x1 +4x2 <=24

x1, x2, x3, x4>=0; x3<=5

c=[-400,-1000,-300,200]; %

A=[0 -2 1 1; 2 3 0 0; 3 4 0 0]; %

b=[0; 16; 24];

xLB=[0,0,0,0]; % x

xUB=[inf,inf,5,inf]; % x

x0=[0,0,0,0]; % x

nEq=1; % = ,<=

x=lp(c,A,b,xLB,xUB,x0,nEq)

disp([': ',num2str(c*x)])


1

x=constr('f ',x0)

fminbnd


1

(01)

[x,fval,exitflag,output]=fminbnd('(x^3+cos(x)+x*log(x))/exp(x)',0,1)


1

[05]

MATLABM

function f = myfun(x)

f = (x-3).^2 - 1;

myfun.m

x=fminbnd(@myfun,0,5)


1

[]

Min f(x)=-x1x2x3,

-x1-2x2-2x30,

x1+2x2+2x372,

: x = [10; 10; 10]

x = [10; 10; 10]

%M myfun.m

function [f,g]=myfun(x)

f=-x(1)*x(2)*x(3);

g(1)=-x(1)-2*x(2)-2*x(3);

g(2)=x(1)+2*x(2)+2*x(3)-72;

%

%MATLAB

x0=[10,10,10];

x=constr('myfun',x0) %


1

]

Min f(x)=-x1x2

(x1+ x2)x3<=0;

x1, x2>=0; x3>=2;

[M fxxgh.m

function [F,G]=fxxgh(x)

F=-x(1)*x(2);

G(1)=(x(1)+x(2))*x(3)-120;

MATLAB

x=[1,1,1]; % x

options(13)=0; % 0 = ,<=

XL=[0,0,2]; % x

XU=[inf;inf;inf]; % x

[x,options]=constr('fxxgh',x,options,XL,XU);

options(8) %

x


1

x

fmins


1

X=fminsearch('2*x(1)^3+4*x(1)*x(2)^3-10*x(1)*x(2)+x(2)^2', [0,0])

MATLAB

function f=myfun(x)

f=2*x(1)^3+4*x(1)*x(2)^3-10*x(1)*x(2)+x(2)^2;

myfun.m

X=fminsearch ('myfun', [0,0]) >> X=fminsearch(@myfun, [0,0])


1

fminunc

2fminuncfminsearch

fminsearch

fun='3*x(1)^2+2*x(1)*x(2)+x(2)^2';

x0=[1 1];

[x,fval,exitflag,output,grad,hessian]=fminunc(fun,x0)

fun=inline('3*x(1)^2+2*x(1)*x(2)+x(2)^2')

x0=[1 1]

x=fminunc(fun,x0)


1

sub.to

fmincon

xbbeqlbubAAeq

C(x)Ceq(x)

f(x)

f(x)C(x)Ceq(x)


1

01

min

s.t

min

s.t


1

MATLAB

function [c, ceq]=mycon (x)

c=(x(1)-1)^2-x(2);

ceq=[ ]; %

M

fun='x(1)^2+x(2)^2-x(1)*x(2)-2*x(1)-5*x(2)'; %

x0=[0 1];

A=[-2 3]; %

b=6;

Aeq=[ ]; %

beq=[ ];

lb=[ ]; %x

ub=[ ];

[x,fval,exitflag,output,lambda,grad,hessian]=fmincon(fun,x0,A,b,Aeq,beq,lb,ub,@mycon)


1

quadratic programming

sub.to

quadprog

HAAeqfbbeqlbubx


1

sub.to


1

MATLAB

H = [1 -1;-1 2] ;

f = [-2; -6] ;

A = [1 1;-1 2; 2 1] ;

b = [2; 2;3] ;

lb = zeros(2,1) ;

[x,fval,exitflag,output,lambda] = quadprog(H,f,A,b, [ ] ,[ ] ,lb)


1

fseminf

xbbeqlbubAAeqC(x)Ceq(x)f(x)f(x)C(x)Ceq(x)2


1

mycon.m

function [C,Ceq,K1,K2,S] = mycon(X,S)

%

if isnan(S(1,1)),

S = [0.2 0; 0.2 0];

end

%

w1 = 1:S(1,1):100;

w2 = 1:S(2,1):100;

%

K1 = sin(w1*X(1)).*cos(w1*X(2)) - 1/1000*(w1-50).^2 -sin(w1*X(3))-X(3)-1;

K2 = sin(w2*X(2)).*cos(w2*X(1)) - 1/1000*(w2-50).^2 -sin(w2*X(3))-X(3)-1;

%

C = [ ]; Ceq=[ ];

%

plot(w1,K1,'-',w2,K2,':'),title('Semi-infinite constraints')

MATLABM

fun = 'sum((x-0.5).^2)';

x0 = [0.5; 0.2; 0.3]; % Starting guess

[x,fval] = fseminf(fun,x0,2,@mycon)


1


1

myfun.mfunction f = myfun(x)

f(1)= 2*x(1)^2+x(2)^2-48*x(1)-40*x(2)+304;

f(2)= -x(1)^2 - 3*x(2)^2;

f(3)= x(1) + 3*x(2) -18;

f(4)= -x(1)- x(2);

f(5)= x(1) + x(2) - 8;

x0 = [0.1; 0.1]; %

[x,fval] = fminimax(@myfun,x0)


1

M

x0 = [0.1; 0.1]; %

options = optimset('MinAbsMax',5); %

[x,fval] = fminimax(@myfun,x0,[ ],[ ],[ ],[ ],[ ],[ ],[ ],options)


1

fgoalattain


1

()1


1

x=[0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1];

y=[-.447 1.978 3.28 6.16 7.08 7.34 7.66 9.56 9.48 9.30 11.2];

n=2; % polynomial order

p=polyfit(x, y, n)

polyfit

y = 9.8108x2 20.1293x0.0317

ezplot('-9.8108*x*x+20.1293*x-0.0317')

xi=linspace(0, 1, 100); % x-axis data for plotting

z=polyval(p, xi);

xiMATLABpolyval

plot(x, y, ' o ' , x, y, xi, z, ' : ' )

xy'o'' : 'xiz

xlabel(' x '), ylabel(' y=f(x) '), title(' Second Order Curve Fitting ')


1

x1=linspace(0, 2*pi, 60);

x2=linspace(0, 2*pi, 6);

plot(x1, sin(x1), x2, sin(x2), ' - ')

xlabel(' x '), ylabel(' sin(x) ')

title(' Linear Interpolation ' )


1

3333interp13


1

12MATLAB

hours=1:12; % index for hour data was recorded

temps=[5 8 9 15 25 29 31 30 22 25 27 24]; % recorded temperatures

plot(hours, temps, hours, temps,' + ') % view temperatures

title(' Temperature ')

xlabel(' Hour '), ylabel(' Degrees Celsius ')

t=interp1(hours, temps, 9.3, ' spline ') % estimate temperature at hour=9.3

t=interp1(hours, temps, 4.7, ' spline ') % estimate temperature at hour=4.7

t=interp1(hours, temps, [3.2 6.5 7.1 11.7], ' spline ')


1


1

,

hours=1:12; % index for hour data was recorded

h=1:0.1:12; % estimate temperature every 1/10 hour

temps=[5 8 9 15 25 29 31 30 22 25 27 24];

t=interp1(hours, temps, h) ;

plot(hours, temps, ' - ' , hours, temps, ' + ' , h, t) % plot comparative results

title(' Springfield Temperature ')

xlabel(' Hour '), ylabel(' Degrees Celsius ')


1

2

MATLABinterp2

Z1=interp2(X,Y,Z,X1,Y1,'method')

X,YZX1,Y1Z1 methodX,Y,Z

X1,Y1X,YNaN


1

10x0:2.5:10()h0:30:60()T()201TI

x=0:2.5:10;

h=[0:30:60]';

T=[95,14,0,0,0;88,48,32,12,6;67,64,54,48,41];

xi=[0:10];

hi=[0:20:60]';

TI=interp2(x,h,T,xi,hi)


  • Login