2015 사회과학원여름수학캠프 : 컴퓨터활용실습 (1 일 ) 1 변수함수의그래프확인하기 - R을활용하여 sin 등의그래프확인하기 # 1. f(x)= sin(1/x) f = function(x) sin(1/x) par(mfcol=c(3,1)) x = seq(-2,2,0.

Similar documents
Vector Differential: 벡터 미분 Yonghee Lee October 17, 벡터미분의 표기 스칼라미분 벡터미분(Vector diffrential) 또는 행렬미분(Matrix differential)은 벡터와 행렬의 미분식에 대 한 표

PowerPoint 프레젠테이션

Microsoft PowerPoint - MDA 2008Fall Ch2 Matrix.pptx

예제 1.1 ( 관계연산자 ) >> A=1:9, B=9-A A = B = >> tf = A>4 % 4 보다큰 A 의원소들을찾을경우 tf = >> tf = (A==B) % A

R-1: R intro. & Objects

<32332D322D303120B9E6BFB5BCAE20C0CCB5BFC1D6312D32302E687770>

Python과 함께 배우는 시스템 해석 - 부록 A.과학계산용 Python 프로그래밍 기초 A-2. Numpy, Matplotlib, Scipy, Sympy 소개

436 8., {(x, y) R 2 : y = x, < x 1} (, 1] φ(t) = (t, t), (, 2] ψ(t) = (t/2, t/2), [1, ) σ(t) = (1/t, 1/t).. ψ φ, σ φ. (φ, I) φ(i) φ : I φ(i). 8.2 I =

π >> x=linspace(0,2*pi,30); >> y=sin(x); >> plot(x,y) π

PowerPoint Presentation

초4-1쌩큐기본(정답)본지

1 경영학을 위한 수학 Final Exam 2015/12/12(토) 13:00-15:00 풀이과정을 모두 명시하시오. 정리를 사용할 경우 명시하시오. 1. (각 6점) 다음 적분을 구하시오 Z 1 4 Z 1 (x + 1) dx (a) 1 (x 1)4 dx 1 Solut


Python과 함께 배우는 신호 해석 제 5 강. 복소수 연산 및 Python을 이용한 복소수 연산 (제 2 장. 복소수 기초)

완벽한개념정립 _ 행렬의참, 거짓 수학전문가 NAMU 선생 1. 행렬의참, 거짓개념정리 1. 교환법칙과관련한내용, 는항상성립하지만 는항상성립하지는않는다. < 참인명제 > (1),, (2) ( ) 인경우에는 가성립한다.,,, (3) 다음과같은관계식을만족하는두행렬 A,B에

1 1 장. 함수와극한 1.1 함수를표현하는네가지방법 1.2 수학적모형 : 필수함수의목록 1.3 기존함수로부터새로운함수구하기 1.4 접선문제와속도문제 1.5 함수의극한 1.6 극한법칙을이용한극한계산 1.7 극한의엄밀한정의 1.8 연속

5Àå-1.hwp


[상반기 결산] ①아파트

HWP Document

fx-82EX_fx-85EX_fx-350EX

Microsoft PowerPoint - LA_ch6_1 [호환 모드]


<4D F736F F F696E74202D204D41544C4142B0ADC0C7B7CF28B9E8C6F7BFEB295F3031C0E55FBDC3C0DBC7CFB1E22E BC8A3C8AF20B8F0B5E55D>

Microsoft PowerPoint - 기계공학실험1-1MATLAB_개요2D.pptx

(001~042)개념RPM3-2(정답)

abstract.dvi

Microsoft Word - igiari-1(KOREAN)_2.doc

LiDAR A utomatic D etection for Misclassified A erial LiD A R D TD


(Microsoft PowerPoint - Ch21_NumAnalysis.ppt [\310\243\310\257 \270\360\265\345])

Buy one get one with discount promotional strategy

PowerPoint Presentation

Chapter 연습문제답안. y *sin-*cos*^ep-*/sqrt. y [ ; sinpi/ ; sin*pi ; ] 혹은 [ sinpi/ sin*pi ]. a ais[- ] b et.,., sin. c.. a A는주어진행렬 M의 번째열만을표시하는새로운행렬을나타낸다.

-주의- 본 교재는 최 상위권을 위한 고난이도 모의고사로 임산부 및 노약자의 건강에 해로울 수 있습니다.

<B1B9BEEE412E687770>

MATLAB for C/C++ Programmers

歯02-BooleanFunction.PDF

04-sa01-91.hwp

PowerPoint Presentation

통신이론 2 장주파수해석 성공회대학교 정보통신공학과 1

<C7D1B1B9B0E6C1A6BFACB1B8C7D0C8B828C0CCC1BEBFF85FC0CCBBF3B5B75FBDC5B1E2B9E9292E687770>

R R ...

LM_matrix.pages

0 cm (++x)=0 x= R QR Q =R =Q = cm =Q =-=(cm) =R =x cm (x+) = +(x+) x= x= (cm) =+=0 (cm) =+=8 (cm) + =0+_8= (cm) cm + = + = _= (cm) 7+x= x= +y= y=8,, Q

<B4EBC7D0BCF6C7D02DBBEFB0A2C7D4BCF62E687770>

Microsoft PowerPoint - 7_배열_문자열

ÀÎÅͳÝ-°ø°£µµÇüÇØ

Microsoft PowerPoint Predicates and Quantifiers.ppt

SRC PLUS 제어기 MANUAL

Microsoft Word - matlab_manual.doc

7. 인실수 에대하여 log 의지표를 이라할때, 옳 은것을보기에서모두고르면? ( 단, 는 를넘지않는최대의정수이다.) 7 ) ㄱ. log ㄴ. log 의지표는 이다. ㄷ. log log 이면 은 자리의정수 이다. 10. 다음은어느인터넷사이트의지도상단에있는버튼의기능을설명한

2005 7

(001~008)고등기본서Ⅰok

<BCF6B8AEBFB5BFAA28B0A1C7FC295FC2A6BCF62E687770>

슬라이드 1

PowerPoint Presentation

MATLAB and Numerical Analysis

Ⅰ. Introduction 우리들을 둘러싸고 잇는 생활 환경속에는 무수히 많은 색들이 있습니다. 색은 구매의욕이나 기호, 식욕 등의 감각을 좌우하는 것은 물론 나뭇잎의 변색에서 초목의 건강상태를 알며 물질의 판단에 이르기까지 광범위하고도 큰 역할을 하고 있습니다. 하

(001~007)수능기적(적통)부속

15인플레이션01-목차1~9

Chapter4.hwp

금안13(10)01-도비라및목차1~13

수리영역 5. 서로다른두개의주사위를동시에던져서나온두눈의수의곱 이짝수일때, 나온두눈의수의합이 또는 일확률은? 5) 의전개식에서상수항이존재하도록하는모든자 연수 의값의합은? 7) 다음순서도에서인쇄되는 의값은? 6) 8. 어떤특산

587.eps

#수Ⅱ지도서-4단( )

Chap 6: Graphs

PowerPoint 프레젠테이션

( )EBS문제집-수리

G5 G25 H5 I5 J5 K5 AVERAGE B5 F5 AVERAGE G5 G24 MAX B5 F5 MIN B5 F5 $G$ $H$25 $G$25 $G$ $H$25 G24 H25 H24 I24 J24 K24 A5 A24 G5 G24, I5

10김묘선

슬라이드 1

13일등예감수학1-1정답(077~120)

제 2 교시 2019 학년도 3 월고 1 전국연합학력평가문제지수학영역 1 5 지선다형 1. 의값은? [2점] 일차방정식 의해는? [2 점 ] 두수, 의최대공약수는? [2 점 ] 일차함수 의그래프에서

A y y y y y # 2#

01

Unknown

확률 및 분포

Vector Space Vector space : 모든 n 차원컬럼벡터의집합 : {, :, } (, 2), (2, 5), (-2.4, 3), (2.7, -3.77), (,), 이차원공간을모두채움 : {,, :,, } (2,3,4), (3,2,-5), Vector spa

Microsoft PowerPoint - statics_vector_and_matrix(노트).ppt

Microsoft PowerPoint - Java7.pptx

public key private key Encryption Algorithm Decryption Algorithm 1

(JBE Vol. 21, No. 1, January 2016) (Regular Paper) 21 1, (JBE Vol. 21, No. 1, January 2016) ISSN 228


DBPIA-NURIMEDIA

보건복지분야 수립 관 연구 본 연구결과는 연구자들의 인적인 의견임을 밝혀둡니다.

Advanced Engineering Mathematics

MATLAB for C/C++ Programmers

<C6EDC1FDBABB2DB5F0C0DAC0CEBAD0BEDF2E687770>

hwp

11기계제도(005~102)

Microsoft PowerPoint 다변수 방정식과 함수(1).ppt

PowerPoint 프레젠테이션

프로그래밍개론및실습 2015 년 2 학기프로그래밍개론및실습과목으로본내용은강의교재인생능출판사, 두근두근 C 언어수업, 천인국지음을발췌수정하였음

01-OOPConcepts(2).PDF

소성해석

歯엑셀모델링

MATLAB for C/C++ Programmers

차례 제 1 장 MATLAB 연습 MATLAB에서사용되는기호들

(Exposure) Exposure (Exposure Assesment) EMF Unknown to mechanism Health Effect (Effect) Unknown to mechanism Behavior pattern (Micro- Environment) Re

Transcription:

2015 사회과학원여름수학캠프 : 컴퓨터활용실습 (1 일 ) 1 변수함수의그래프확인하기 - R을활용하여 sin 등의그래프확인하기 # 1. f(x)= sin(1/x) f = function(x) sin(1/x) par(mfcol=c(3,1)) x = seq(-2,2,0.0001) plot(y~x, type='l', xlim=c(-2,2)) x = seq(-2,2,0.0001) plot(y~x, type='l', xlim=c(-0.5, 0.5)) x = seq(-2,2,0.00001) plot(y~x, type='l', xlim=c(-0.1, 0.1)) x = seq(-0.01,0.01,0.0000001) plot(y~x, type='l', xlim=c(-0.01, 0.01)) # 2. f(x) = x* sin(1/x) f = function(x) x*sin(1/x) par(mfcol=c(3,1)) x = seq(-2,2,0.0001) plot(y~x, type='l', xlim=c(-2,2)) x = seq(-0.5,0.5,0.0001) plot(y~x, type='l', xlim=c(-0.5, 0.5)) x = seq(-0.1,0.1,0.00001) plot(y~x, type='l', xlim=c(-0.1, 0.1)) # 2. f(x) = x* sin(1/x); f'(x)=2xsin(1/x)-cos(1/x) f = function(x) 2*x*sin(1/x)-cos(1/x) par(mfcol=c(3,1)) x = seq(-2,2,0.0001); plot(y~x, type='l', xlim=c(-2,2)) x = seq(-0.5,0.5,0.0001) plot(y~x, type='l', xlim=c(-0.5, 0.5)) x = seq(-0.1,0.1,0.00001) ; plot(y~x, type='l', xlim=c(-0.1, 0.1))

# 3. f(x) = x^2* sin(1/x) f = function(x) x^2*sin(1/x) par(mfcol=c(1,1)) x = seq(-2,2,0.0001) plot(y~x, type='l', xlim=c(-2,2)) x = seq(-0.5,0.5,0.0001) plot(y~x, type='l', xlim=c(-0.5, 0.5)) x = seq(-0.1,0.1,0.00001) plot(y~x, type='l', xlim=c(-0.1, 0.1)) - 그밖의다른사이트 https://www.desmos.com/calculator cos sin 함수 가 (0,1) 주위에서어떤모양을취하는지확인하자. www.wolframalpha.com plot(cos x, {x, -1,1}) http://sage.skku.edu/ plot(sin(1/x))

컴퓨터프로그램을활용한미분과적분 Wolfram alpha http://www.wolframalpha.com/ D(cos x) integrate(cos x) http://www.wolframalpha.com/calculators/integral-calculator/ http://sage.skku.edu/ diff(x^2, x) integrate(x^2,x) integrate(log(x),x) integrate(exp(-1/2*x^2), x, -infinity, infinity) R dx2x <- deriv(~ x^2, "x") ; dx2x mode(dx2x) x <- -1:2 eval(dx2x) And many more others. Maxima, Mathics, SymPy, etc.

R 로하는수치적적분 (Numerical Integration in R) 1. 1차원함수의적분 (integrate) 가 ) 함수정의 f = function(x) {... } 나 ) 적분하기 integrate(f, lower=, upper= ) f.norm1d =function(x) { 1/sqrt(2*pi)*exp(-1/2*x^2) } integrate(f.norm1d, lower=-inf, upper=inf) c3 = function(x) (x^2-2*x+3) integrate(c3, lower=0, upper=1) curve(f.norm1d, xlim=c(-6,6)) curve(c3, xlim=c(0,1)) 2. 2차원함수의적분 (cubature::adaptintegrate, R2Cuba::cuhre) 가 ) 함수정의 f=function(x) { x[1]^2 + x[2]^2 } 나 ) 적분하기 adaptintegrate(f, lowerlimit=c(, ), upperlimit=c(, )) cuhre(2, 1, f, lower=c(, ), upper=c(, )) e1 = function(x) 1/(1-x[1]*x[2]) e3 = function(x) (2-x[1]-x[2])^(-1/2) e4 = function(x) (3-x[1]-2*x[2])^(-1/2) e6 = function(x) abs(x[1]^2 + x[2]^2-0.25) e7 = function(x) abs(x[1]-x[2])^(1/2) adaptintegrate(e1, lowerlimit = c(0,0), upperlimit = c(1,1)) # pi^2/6 cuhre(2, 1, e1, lower=c(0,0), upper=c(1, 1)) vegas(2, 1, e1, lower=c(0,0), upper=c(1, 1)) emdbook::curve3d(e1(c(x,y)), from=c(-1,-1), to=c(1,1), sys3d = "contour") curve3d(e1(c(x,y)), from=c(-1,-1), to=c(1,1), sys3d = "wireframe") curve3d(e1(c(x,y)), from=c(-1,-1), to=c(1,1), sys3d = "rgl") curve3d(e1(c(x,y)), from=c(-1,-1), to=c(1,1), sys3d = "persp")

2015 사회과학원여름수학캠프 : 컴퓨터활용실습 (2일) R로하는수치미적분 CAS를활용하여방정식풀기방정식의수치적해풀기 R의최적화를활용한회귀분석 R 로하는수치적미분 (Numerical Derivation) library(numderiv) f = function(x) { a = x[1]; b = x[2]; c = x[3]; a^2+b*c-exp(c*a) } grad(f, x=c(1,1,1)) hessian(f, x=c(1,1,1))

R 로하는수치적적분 (Numerical Integration in R) 1. 1차원함수의적분 (integrate) 가 ) 함수정의 f = function(x) {... } 나 ) 적분하기 integrate(f, lower=, upper= ) f.norm1d =function(x) { 1/sqrt(2*pi)*exp(-1/2*x^2) } integrate(f.norm, lower=-inf, upper=inf) c3 = function(x) (x^2-2*x+3) integrate(c3, lower=0, upper=1) curve(f.norm1d, xlim=c(-6,6)) curve(c3, xlim=c(0,1)) 2. 2차원함수의적분 (cubature::adaptintegrate, R2Cuba::cuhre) 가 ) 함수정의 f=function(x) { x[1]^2 + x[2]^2 } 나 ) 적분하기 adaptintegrate(f, lowerlimit=c(, ), upperlimit=c(, )) cuhre(2, 1, f, lower=c(, ), upper=c(, )) e1 = function(x) 1/(1-x[1]*x[2]) e3 = function(x) (2-x[1]-x[2])^(-1/2) e4 = function(x) (3-x[1]-2*x[2])^(-1/2) e6 = function(x) abs(x[1]^2 + x[2]^2-0.25) e7 = function(x) abs(x[1]-x[2])^(1/2) adaptintegrate(e1, lowerlimit = c(0,0), upperlimit = c(1,1)) # pi^2/6 cuhre(2, 1, e1, lower=c(0,0), upper=c(1, 1)) vegas(2, 1, e1, lower=c(0,0), upper=c(1, 1)) emdbook::curve3d(e1(c(x,y)), from=c(-1,-1), to=c(1,1), sys3d = "contour") curve3d(e1(c(x,y)), from=c(-1,-1), to=c(1,1), sys3d = "wireframe") curve3d(e1(c(x,y)), from=c(-1,-1), to=c(1,1), sys3d = "rgl") curve3d(e1(c(x,y)), from=c(-1,-1), to=c(1,1), sys3d = "persp")

이변수함수그래프그리기 http://www.math.uri.edu/~bkaskosz/flashmo/graph3d/ wxmaxima http://gkerns.people.ysu.edu/maxima/maximaintro/maximaintro.pdf f(x, y) := x^2 + y^2; load(draw); draw3d(explicit(f(x,y), x, -3, 3, y, -3, 3)); Basic Algebra and Calculus in SAGE http://doc.sagemath.org/html/en/tutorial/tour_algebra.html 방정식풀기 2 차방정식 x=var('x') solve(x^2 + 2*x + 1, x) 계수가변수인 x, a, b, c=var('x a b c') solve([a*x^2+b*x+c==0], x) 2 원 1 차방정식 x, y = var('x, y') solve([x+y==4, x-y==2], x,y) 3 원방정식 var('x y z') eq1 = x+y==4 eq2 = x^2+y^2==5 eq3 = x*y*z= 3 solve([eq1, eq2, eq3], x, y, z) 수치해 (find_root, 범위 ) theta=var('theta') find_root(cos(theta)==sin(theta), 0, pi/2)

R 의최적화를활용한회귀분석 Regression : minimize Lasso Regression : minimize Ridge Regression : minimize reg=function(param) { b0=param[1]; b1=param[2]; b2=param[3] (b0+b1+5*b2-4)^2+(b0+b1*3+b2*4-5)^2+(b0+b1*5+b2*4-2)^2+(b0+b1^2+ 6*b2-3)^2 } reg.lasso=function(param, lambda=1) { b0=param[1]; b1=param[2]; b2=param[3] (b0+b1+5*b2-4)^2+(b0+b1*3+b2*4-5)^2+(b0+b1*5+b2*4-2)^2+(b0+b1^2+ 6*b2-3)^2+ lambda*(abs(b1)+abs(b2)) } reg.ridge=function(param, lambda=1) { b0=param[1]; b1=param[2]; b2=param[3] (b0+b1+5*b2-4)^2+(b0+b1*3+b2*4-5)^2+(b0+b1*5+b2*4-2)^2+(b0+b1^2+ 6*b2-3)^2+ lambda*(b1^2+b2^2) } optimx(par=c(b0=1, b1=1, b2=1), fn=reg, control=list(all.methods=t)) optimx(par=c(b0=1, b1=1, b2=1), fn=reg.lasso, control=list(all.methods=t)) optimx(par=c(b0=1, b1=1, b2=1), fn=reg.ridge, control=list(all.methods=t)) optimx(par=c(b0=0, b1=0, b2=0, lambda=1), fn=reg.ridge, control=list(all.methods=t)) optim(par=c(b0=0, b1=0, b2=0, lambda=0), fn=reg.ridge, method="bfgs") optim(par=c(b0=0, b1=0, b2=0, lambda=1), fn=reg.ridge, method="bfgs")

x1, x2 가주어졌을때 x1=c(1,3,5,2) x2=c(5,4,4,6) y=c(4,5,2,3) f=function(b) { b0=b[1]; b1=b[2]; b2=b[3]; sum((b0+b1*x1+b2*x2-4)^2) } optim(c(1,1,1), f) optim(c(1,1,1), f, method="bfgs") lm(y~x1+x2) # 위의결과와비교

R 과 LaGrange Multiplier 를활용하여최적화 비교 SAGE var('x y z p q') eq1 = 2*x-2*p-q==0 eq2 = 2*y+p-q==0 eq3 = 2*z-5*q==0 eq4 = 2*x+y-3==0 eq5 = 10*x-y+5*z==0 solve([eq1, eq2, eq3, eq4, eq5],x,y,z,p,q) R: LaGrange Multiplier 이용 eqs = function(param) { x= param[1]; y= param[2]; z=param[3]; p=param[4]; q=param[5]; c(2*x-2*p-q, 2*y+p-q, 2*z-5*q, 2*x+y-3, 10*x-y+5*z) } sol = nleqslv(c(1,1,1,1,1), eqs) 문제 maximize ln s.t ln -2*c*x+2*x+3*y-p-r*(a+b^2/x) 3*x-p 0-p b-q*(2*a)-r*x a-q*(-2*b)-2*b*log(x) -2*c+1/c-x^2-q*(2*c) x+y+z-10=0 a^2+b^2+c^2-9 a*x+b^2*log(x)-5

2015 사회과학원여름수학캠프 : 컴퓨터활용실습 (3 일 ) R 로하는행렬연산 행렬만들기 A=matrix(c(1,2,3,4), nrow=2, ncol=2, byrow=f) B=matrix(c(1,2,3,4), nrow=2, ncol=2, byrow=t) C=matrix(c(1,2,3,4), nrow=4, ncol=1, byrow=f) D=matrix(c(1,2,3,4), nrow=1, ncol=4, byrow=t) 다음행렬을변수 E, F 에저장해보자., 주의! C,D,F 는이미이름이배정되어있다. 따라서 C1, D1, E1 으로저장하자. 행렬의덧셈, 뺄셈, 곱셈, 실수배, 역행렬 A+B A-B A-C1 A %*% B C1 %*% D1 C1 %*% A 3*A solve(a) 전치행렬 t(a) 대각합 psych::tr(a) # library(psych) 항등행렬 diag(3) diag(rep(1,5)) diag(12) 대칭행렬확인 all(a == t(a)) # A=1/2*(A+t(A)) # A=t(A) %*% A; B=B %*% t(b)

정방행렬확인 (nrow(a)==ncol(a)) 대각행렬 diag(c(1,3,2,4)) diag(c(1,1,1,3,3,3)) 직교행렬확인 (all(t(q) %*% Q == diag(3))) 참고 http://www.statmethods.net/advstats/matrix.html

SAGE 1. 가모두 의하삼각행렬일때, 도하삼각행렬인가? SAGE> var('a b c d e f g h i j k l') A=matrix([[a,0,0],[b,d,0],[c,e,f]]) B=matrix([[g,0,0],[h,j,0],[i,k,l]]) A*B 2. SAGE> A=matrix(QQ,[[1,-3,0,-5],[3,-12,-2,-27],[-2,10,2,24],[-1,6,1,14]]); b=matrix(qq, 4, 1, [-7,-33,29,17]); C=A.augment(b); C.echelon_form() 3. SAGE> A=matrix(QQ,[[0,0,0,1,2,-1],[1,2,0,0,1,-1],[1,2,2,0,-1,1]]); b=matrix(qq, 3, 1, [2,0,2]); C=A.augment(b); C.echelon_form() 4. SAGE> A=matrix(QQ, [[1,3,1,6],[2,2,3,3],[-1,1,0,1]]); b=matrix(qq, 3, 1, [8,14,-2]); C=A.augment(b); C.echelon_form()

5. SAGE> A=matrix(QQ, [[1,2,2,8,0,2,2],[2,4,1,7,1,-1,-5],[-1,-2,1,1,1,0,3],[3,6,3,15,0,3,0]]) b=matrix(qq, 4, 1, [3,0,-2,6]) C=A.augment(b); C.echelon_form()

2015 사회과학원여름수학캠프 : 컴퓨터활용실습 (4 일 ) Visualizing 2-variable function #http://stackoverflow.com/questions/20549540/how-to-create-3d-matlab-style-s urface-plots-in-r for (r_ in c(1,0, 0.5, 0.2, 0.1)) { points = seq(-r_-0.1, r_-0.1, length=20) #create a grid XY = expand.grid(x=points,y=-points) # A z-function Zf <- f # populate a surface Z <- Zf(XY$X, XY$Y) zlim <- range(z) zlen <- zlim[2] - zlim[1] + 1 jet.colors <- # function from grdevices package colorramppalette(c("#00007f", "blue", "#007FFF", "cyan", "#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000")) colorzjet <- jet.colors(100) # 100 separate color require(rgl) open3d() rgl.surface(x=points, y=matrix(z,20), coords=c(1,3,2),z=-points, color=colorzjet[ findinterval(z, seq(min(z), max(z), length=100))] ) axes3d() rgl.snapshot("copymatlabstyle.png") }

covariance matrix of linear transfomation of random vectors X <- matrix(rnorm(3*n.subj), nrow=3) A <- matrix(c(0.5, 0.4, -0.3, 0.1, -0.6, 0.1, 0.5, 0.1, -0.2, 0.05, -0.5, -0.1, 0.5, 0.1, 0.4, 0.4, -0.15, 0.01, 0.1, 0.0, 0.1), ncol=3, byrow=t) sigma1 = cov(t(a %*% X)) sigma2 = A %*% cov(t(x)) %*% t(a) sigma1 == sigma2 all.equal(sigma1, sigma2) # Almost true?

PCA n.subj <- 100 pc <- matrix(rnorm(3*n.subj), nrow=3) A <- matrix(c(0.5, 0.4, -0.3, 0.1, -0.6, 0.1, 0.5, 0.1, -0.2, 0.05, -0.5, -0.1, 0.5, 0.1, 0.4, 0.4, -0.15, 0.01, 0.1, 0.0, 0.1), ncol=3, byrow=t) dat <- t(a %*% pc) df.dat <- data.frame(dat) plot(df.dat) dat.prcomp <- prcomp(dat, cor=f ) par(mfcol=c(3,3)) cor(pc[1,],dat.prcomp$x[,"pc1"]); plot(pc[1,],dat.prcomp$x[,"pc1"]) cor(pc[2,],dat.prcomp$x[,"pc1"]); plot(pc[2,],dat.prcomp$x[,"pc1"]) cor(pc[2,],dat.prcomp$x[,"pc1"]); plot(pc[3,],dat.prcomp$x[,"pc1"]); cor(pc[1,],dat.prcomp$x[,"pc2"]) cor(pc[2,],dat.prcomp$x[,"pc2"]) cor(pc[3,],dat.prcomp$x[,"pc2"]) cor(pc[1,],dat.prcomp$x[,"pc3"]) cor(pc[2,],dat.prcomp$x[,"pc3"]) cor(pc[3,],dat.prcomp$x[,"pc3"]) factanal(dat, factors=3) solve(cor(dat)) det(cor(dat))

eigen decomposition A.eigen <- eigen(a) A.eigen$val A.eigen$vec # 대칭행렬 A 가양의정부호 (positive definite) 행렬임을확인하는방법은? # 교재 45 쪽의 행렬을구성해보자. # 은대칭행렬인가? # 은정사영행렬인가?

PCA 와 MDS 비교 # from http://www.statmethods.net/advstats/mds.html library(mass) S=matrix(c(1,0.7,0.7,0.8), ncol=2) dat <- mvrnorm(n=1000, mu=c(0,0), S) d <- dist(dat) # euclidean distances between the rows fit <- cmdscale(d,eig=true, k=1) # k is the number of dim fit # view results MDS1 <- fit$points[,1] MDS2 <- fit$points[,2] dat.scale <- scale(dat, scale=f) apply(dat.scale, 2, mean) cov.dat.scale <- t(dat.scale) %*% dat.scale eigen(cov.dat.scale) dat.pca <- prcomp(dat, center = TRUE, scale. = F) PC1 <- dat.pca$x[,"pc1"] PC2 <- dat.pca$x[,"pc2"] plot(mds1, PC1) plot(dat[,1], dat[,2]) plot(mds1, MDS2) plot(pc1, PC2)