Le-(7)matlab编程习题_第1页
Le-(7)matlab编程习题_第2页
Le-(7)matlab编程习题_第3页
Le-(7)matlab编程习题_第4页
Le-(7)matlab编程习题_第5页
已阅读5页,还剩18页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、2009-4-131 Computer Simulation s=1; while s2000 n=n+1; s=s+n; end n-1 验证程序:验证程序: s=1; for i=2:62; s=s+i; end s 【 【s1953】 若改成函数文件呢?若改成函数文件呢? 例:任意参数例:任意参数SUM,编写函数 文件 ,编写函数 文件my_max_sum,求出使,求出使 1+2+nSUM的的n值值 2009-4-135 Computer Simulation for i=n1:n2 sum=sum+2i; end 调用方法:调用方法: Sum=mysum(0,15) %【s65535】

2、 用用while循环循环 sum=0,i=n1; while i=0 else y=0; end ,01 ( )2,12 0, xx f xxx others = ( 3),( 2),( )fff 调用方法:调用方法: ff(-3) % 0 ff(sqrt(2) % 0.5858 ff(inf) %0 2009-4-138 Computer Simulation end sum=0; for i=1:2:(2*n+1) sum=sum+i; end 调用方法:调用方法: sum=mysum2 %N=1, 2, 3 %Sum=4, 9,16 2009-4-139 Computer Simulat

3、ion plot(t,f); title(f(t)=Sa(t); xlabel(t); axis(-10,10,-0.4,1.1); 2009-4-1310 Computer Simulation y=3*sin(2*pi*50*t); plot(t(1:50),y(1:50); t=0:0.001:50; y=sin(2*pi*50*t); s=y+randn(size(t); plot(t(1:50),s(1:50); 2009-4-1311 Computer Simulation y=square(2*pi*30*t); plot(t(1:50),y(1:50); t=0:0.001:2

4、.5; y=sawtooth(2*pi*30*t); plot(t,y); axis(0 0.2 1 1); 2009-4-1312 Computer Simulation y1=sinc(t); Subplot(121) plot(t,y1); y2=sin (t)./t; Subplot(122) plot(t,y2); % y1 = sin(pi*t)/(pi*t) 2009-4-1313 Computer Simulation ezplot(sin(pi/4*t),-16,16); 2009-4-1315 Computer Simulation f= sin(pi/4*t) 例:例:

5、a=1;b=-2;c=1; f=(x)(a*x.2+b*x+c); ezplot(f) 例:a=pi,b=15; f=(x,y)(a*x+b*y); ezsurf(f) 例: f=(x)(x.2); g=(x)(3*x); h=(x)(g(f(x) h(3) 2009-4-1316 Computer Simulation fplot(x)f(x,10),0 2*pi) 2009-4-1318 Computer Simulation c = 1.5; % define parameter first x = fminbnd(x) myfun(x,c),0,1) 2009-4-1319 Compu

6、ter Simulation c = 2; % define parameter first x = fzero(x) myfun(x,c),0.1) 2009-4-1320 Computer Simulation where myfun.m is the M-file function: %-% function y = myfun(x) y = 1./(x.3-2*x-5); %-% 2009-4-1321 Computer Simulation y(i)=quad(humps,0,x(i); end plot(x,y) 2009-4-1322 Computer Simulation & ApplicationComputer Simulation & Application 本课小结本课小结 读写文件,设置路径等读写文件,设置路径等 编程方法编程方法 任意函数的定义方法任意函数的定义方法 函数库函数库 2009-4-1323 Computer Simulation & Applicati

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论