资源描述:
《复旦大学matlab课件—— (8)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、MatlabMathCleveMorler著陈文斌(wbchen@fudan.edu.cn)复旦大学2002年http://www.stanford.edu/class/cs138/mlmath.html黄金分割p=[1–1–1];r=roots(p);r=-0.618033988749891.61803398874989C(1)*X^N+...+C(N)*X+C(N+1)=0r=solve(‘1/x=x-1’);r=[1/2*5^(1/2)+1/2][1/2-1/2*5^(1/2)]符号工具箱Mapplephi=r(1)vpa(phi,50)1
2、/2*5^(1/2)+1/21.6180339887498948482045868343656381177203091798058phi=double(phi)1.61803398874989图形的方法f=inline('1/x-(x-1)')ezplot(f,0,4)phi=fzero(f,1)holdonplot(phi,0,’o’)00.511.522.533.54-3-2-101234567x1/x-(x-1)结果图ff-111黄金分割图%GOLDRECTGoldenRectangle%GOLDRECTplotsthegoldenrect
3、anglephi=(1+sqrt(5))/2;x=[0phiphi00];y=[00110];u=[11];v=[01];plot(x,y,'b',u,v,'b--');text(phi/2,1.05,'phi')text((1+phi)/2,-.05,'phi-1');text(-.05,.5,'1');text(.5,-.05,'1')axisequalaxisoffset(gcf,'color','white')连分式连分式Goldfract.mg=1+1/(1+1/(1+1/(1+1/(1+1/(1+1/(1))))))g=21/13
4、g=1.61538461538462err=0.0026字符串有效数字2位FibonacciLeonardoPisanoFibonacciwasbornaround1170anddiedaround1250inPisainwhatisnowItaly.HetraveledextensivelyinEuropeandNorthernAfrica.Hewroteseveralmathematicaltextsthat,amongotherthings,introducedEuropetotheHindu-Arabicnotationfornumber
5、s.Eventhoughhisbookshadtobetranscribedbyhand,theywerestillwidelycirculated.Inhisbestknownbook,LiberAbaci,publishedin1202,heposedthefollowingproblem.Amanputapairofrabbitsinaplacesurroundedonallsidesbyawall.Howmanypairsofrabbitscanbeproducedfromthatpairinayearifitissupposedthat
6、everymontheachpairbegetsanewpairwhichfromthesecondmonthonbecomesproductive?兔子的故事兔子从出生要一个月,从出生到成熟要过一个月月123456繁殖111235出生011235成熟001123总数1235813Fibonacci序列Fibonacci.m123581321345589144233递归实现:Fibnum.m递归实现递归实现是elegantbutexpensivetic,fibnum(24),toctic,fibonacci(24),toc试一下,比较时间!黄金分
7、割和Fibonacci数比较一下goldfract(6)和fibonacci(7)连分式:g=g+f;黄金分割:f(k)=f(k-1)+f(k-2);n=40;f=fibonacci(n);f(2:n)./f(1:n-1)f(2:n)./f(1:n-1)-phiFibonacci的兔子Fibonacci的兔子以黄金分割的速度增长。+有两个解phi和(1-phi)由初始条件:是有理分式Fibonacci的兔子注意:没有半只兔子formatlongen=(1:40)';f=(phi.^(n+1)-(1-phi).^(n+1))/(2*phi-1)f
8、=round(f)魔方阵A=magic(3)sum(A)sum(A’)sum(diag(A))sum(diag(flipud(A)))s