正在加载图片...
Chapter 1. Introduction to MATLAB text(1+phi)/2,-.05,phi-1) text(-.05,5,1) text(.5,-.05,1) axis equa axis off set(gcf, 'color','white') The vectors x and y each contain five elements. Connecting consecutive (k, yk)pairs with straight lines produces the outside rectangle. The vectors u and v each contain two elements. The line connecting(u1, v1)with(u2, u2) sepa- ates the rectangle into the square and the smaller rectangle. The plot command draws these lines-the x-y lines in solid blue and the u-v line in dashed blue The next four statements place text at various points; the string"phi' denotes the Greek letter. The two axis statements cause the scaling in the z and y directions to be equal and then turn off the display of the axes. The last statement sets the background color of gcf, which stands for get current figure, to white A continued fraction is an infinite expression of the form a1+a2+a3+… If all the aks are equal to l, the continued fraction is another representation of the The following MATLAB function generates and evaluates truncated continued frac tion approximations to o. The code is stored in an M-file named goldfract m. function goldfract(n) ZGOLDFRACT Golden ratio continued fraction GOLDFRACT (n) displays n terms P 8b=[1+/(P")1 P end p= sprintf('%d/d',P, q6 Chapter 1. Introduction to MATLAB text((1+phi)/2,-.05,’\phi - 1’) text(-.05,.5,’1’) text(.5,-.05,’1’) axis equal axis off set(gcf,’color’,’white’) The vectors x and y each contain five elements. Connecting consecutive (xk, yk) pairs with straight lines produces the outside rectangle. The vectors u and v each contain two elements. The line connecting (u1, v1) with (u2, v2) sepa￾rates the rectangle into the square and the smaller rectangle. The plot command draws these lines—the x − y lines in solid blue and the u − v line in dashed blue. The next four statements place text at various points; the string ’\phi’ denotes the Greek letter. The two axis statements cause the scaling in the x and y directions to be equal and then turn off the display of the axes. The last statement sets the background color of gcf, which stands for get current figure, to white. A continued fraction is an infinite expression of the form a0 + 1 a1 + 1 a2+ 1 a3+··· . If all the ak’s are equal to 1, the continued fraction is another representation of the golden ratio: φ = 1 + 1 1 + 1 1+ 1 1+··· . The following Matlab function generates and evaluates truncated continued frac￾tion approximations to φ. The code is stored in an M-file named goldfract.m. function goldfract(n) %GOLDFRACT Golden ratio continued fraction. % GOLDFRACT(n) displays n terms. p = ’1’; for k = 1:n p = [’1+1/(’ p ’)’]; end p p = 1; q = 1; for k = 1:n s = p; p = p + q; q = s; end p = sprintf(’%d/%d’,p,q)
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有