您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 经营企划 > 上海复旦大学matlab课件1
MatlabMathCleveMorler著陈文斌(wbchen@fudan.edu.cn)复旦大学2002年黄金分割111111012251p=[1–1–1];r=roots(p);1)(2xxxpr=-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*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)结果图-111黄金分割图%GOLDRECTGoldenRectangle%GOLDRECTplotsthegoldenrectanglephi=(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')连分式...1113210aaaa...1111111连分式Goldfract.mg=1+1/(1+1/(1+1/(1+1/(1+1/(1+1/(1))))))g=21/13g=1.61538461538462err=0.0026字符串有效数字2位FibonacciLeonardoPisanoFibonacciwasbornaround1170anddiedaround1250inPisainwhatisnowItaly.HetraveledextensivelyinEuropeandNorthernAfrica.Hewroteseveralmathematicaltextsthat,amongotherthings,introducedEuropetotheHindu-Arabicnotationfornumbers.Eventhoughhisbookshadtobetranscribedbyhand,theywerestillwidelycirculated.Inhisbestknownbook,LiberAbaci,publishedin1202,heposedthefollowingproblem.Amanputapairofrabbitsinaplacesurroundedonallsidesbyawall.Howmanypairsofrabbitscanbeproducedfromthatpairinayearifitissupposedthateverymontheachpairbegetsanewpairwhichfromthesecondmonthonbecomesproductive?兔子的故事兔子从出生要一个月,从出生到成熟要过一个月月123456繁殖111235出生011235成熟001123总数1235813Fibonacci序列21nnnfff2,120ffFibonacci.m123581321345589144233递归实现:Fibnum.m递归实现递归实现是elegantbutexpensivetic,fibnum(24),toctic,fibonacci(24),toc试一下,比较时间!黄金分割和Fibonacci数比较一下goldfract(6)和fibonacci(7)连分式:g=g+f;黄金分割:f(k)=f(k-1)+f(k-2);nnnff1nnnff1limn=40;f=fibonacci(n);f(2:n)./f(1:n-1)f(2:n)./f(1:n-1)-phiFibonacci的兔子Fibonacci的兔子以黄金分割的速度增长。nncf21nnnfff+12nnnccf)1(21有两个解phi和(1-phi)由初始条件:12)1(,1221cc))1((12111nnnf是有理分式Fibonacci的兔子注意:没有半只兔子formatlongen=(1:40)';f=(phi.^(n+1)-(1-phi).^(n+1))/(2*phi-1)f=round(f)魔方阵A=magic(3)sum(A)sum(A’)sum(diag(A))sum(diag(flipud(A)))sum(1:9)/3816357492魔方阵的八种组合fork=0:3rot90(A,k)rot90(A’,k)end逆时阵旋转k*90度基本代数运算X=inv(A)det(A)-3600.1472-0.14440.0639-0.06110.02220.1056-0.01940.1889-0.1028formatrat53/360-13/9023/360-11/1801/4519/180-7/36017/90-37/360基本代数运算r=norm(A)e=eig(A)s=svd(A)e=15.00004.8990-4.8990s=15.00006.92823.4641r=15NORM(X)isthelargestsingularvalueofX,max(svd(X)).符号计算A=sym(A)sum(A)sum(A’)’det(A)inv(A)eig(A)svd(A)100200300400500100200300400500600图象显示loaddurerwhosimage(X)colormap(map)axisimageMelancolia,aRenaissanceetchingbyAlbrectDurer50100150200250300350501001502002503003504阶魔方阵loaddetailimage(X)colormap(map)axisimage4阶魔方阵16231351110897612414151A=magic(4)A=A(:,[1324])4阶魔方阵:880个5阶魔方阵:275305224个6阶魔方阵:?秩和奇异阵A=magic(4)det(A)inv(A)矩阵的秩是矩阵中线性无关的行和列的个数,一个n阶矩阵是奇异的当且仅当它的秩小于nrank(magic(4))秩和奇异阵forn=1:24,r(n)=rank(magic(n));end[(1:24)’r’]bar(r)tiltle(‘魔方阵的秩’)05101520250510152025n:奇数,满秩n=4k:秩是3n=2k!=4k:秩是n/2+2魔方阵的三维显示surf(magic(n))axisoffset(gcf,’doublebuffer’,’on’)cameratoolbarforn=8:11subplot(2,2,n-7),surf(magic(n))axisoff,view(30,45)%axistightend图形对象小鸭子加密--Matlab字符能力x=reshape(32:127,32,3)’c=char(x)char(32)c=!#$%&'()*+,-./0123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~字符串d=char(48:57)double(d)–‘0’d=0123456789ans=0123456789字符串(高八位)char(reshape(160:255,32,3)’)char(160)char(160:161)牎ⅲぅΗī氨渤吹斗腹夯冀究懒旅呐魄壬仕掏蜗醒矣哉肿刭谯茌捱?模运算x=[37–3737–37]’;y=[1010-10-10]’;r=[xyrem(x,y)mod(x,y)]371077-3710-7337-107-3-37-10-7-7字符加密取素数:P=97(要表示95个字符)x=double(‘TV’)’-32y=AxmodPA=[712226]‘TV’’1U’Ify=AxmodPthenx=AymodPmod(A^2,P)=ICrypto.m‘helloworld’,?{p]~Y&=分形蕨Fern.m数论中未解决的3n+1问题如果n=1,停止如果n是偶数,n=n/2;如果n是奇数,n=3n+1问题:这个过程是否一定会终止?综述文章:AmericanMathematicalMonthly,92(1985),3-23(n)%Threenplus1.%Studythe3n+1sequence.%threenplus1(n)plotsthesequencestartingwithn.%threenplus1withnoargumentsstartswithn=1.%uicontrolsdecrementorincrementthestartingn.%Isitpossibleforthistorunforever?if~isequal(get(gcf,'tag'),'3n+1')shgclfresetuicontrol('position',[26052522],...'string','',...'callback','threenplus1('''')');uicontrol('position',[30052522],...'string','',...'callback','threenplus1('''')');set(gcf,'tag','3n+1');endifnargin==0n=1;elseifisequal(n,'')n=get(gcf,'userdata')-1;elseifisequal(n,'')n=get(gcf,'userdata')+1;endifn1,n=1;endset(gcf,'userdata',n)y=n;whilen1ifrem(n,2)==0n=n/2;elsen=3*n+1;endy=[yn];endsemilogy(y,'.-')axistightymax=max(y);ytick=[2.^(0:ceil(log2(ymax))-1)ymax];iflength(ytick)8,ytick(end-1)=[];endset(gca,'ytick',ytick)title(['n='num2str(y(1))]);x=32768y=0L:lcadyshiftright5bitsaddxstoreinxchangesignshiftright5bitsaddystoreinyplotxygotoL画园h=1/32;x=1;y=0;while1x=x+h*y;y=y-h*x;plot(x,y,’.’)drawnowendCirclegen.m画园111nnnnnnhxyyhyxx画园中的特征值111nnnnnnhxyyhyxxnnnnnnyhhxyhyxx)1(211
本文标题:上海复旦大学matlab课件1
链接地址:https://www.777doc.com/doc-5467566 .html