利用matlab编写S函数求解微分方程_第1页
利用matlab编写S函数求解微分方程_第2页
免费预览已结束,剩余6页可下载查看

下载本文档

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

文档简介

1、实用文案标准文档自动化专业综合设计报告设计题目:利用matlab编与S函数求解微分方程所在实验室:自动化系统仿真实验室指导教师:郭卫平学生姓名律迪迪班级文自 0921学号 200990519114成绩评定:_实用文案标准文档一、设计目的了解使用 simulink 的扩展工具- S-函数,s 函数可以利用 matlab 的丰富资源,而不仅仅局限于 simulink 提供的模块,而用 c 或 C+等语言写的 s 函数还可以实现对硬件端口的操 作,还可以操作 windows API 等的,它的魅力在于完美结合了simulink 框图简洁明快的特点和编程灵活方便的优点,提供了增强和扩展 sin uli

2、 nk能力的强大机制,同时也是使用 RTW实现实时仿真的关键。、设计要求求解解微分方程y =y_2x/yy(o)=i要求利用 matlab 编写 S 函数求解三、设计内容(可加附页)【步骤 1】获取状态空间表达式。在 matlab 中输入dsolve( Dy=y-2*x/y , y(0)=1;x)得到y=(2*x+1).A(1/2);【步骤 2】建立 s 函数的 m 文件。利用 21 用 S 函数模板文件。 以下是修改之后的模板文件 sfun tmpl.m 的内容。function sys,xO,str,ts = sfun tmpl(t,x,u,flag)%SFUNTMPL General M

3、-file S-fu nctio n template% With M-file S-functions, you can defi ne you own ordinary differe ntial% equati ons (ODEs), discrete system equati ons, an d/or just about% any type of algorithm to be used within a Simulink block diagram.% The gen eral form of an M-File S-fu nctio n syntax is:% SYS,XO,S

4、TR,TS = SFUNC(T,X,U,FLAG,P1,.,P n)% What is retur ned by SFUNC at a give n point in time, T, depe nds on the% value of the FLAG, the curre nt state vector, X, and the curre nt% in put vector, U.% FLAG RESULTDESCRIPTION% _ _ _% 0 SIZES,XO,STR,TS In itializatio n, return system sizes in SYS,实用文案标准文档%i

5、n itial state in X0, state orderi ng stri ngs%in STR, and sample times in TS.%1DXReturn continuous state derivatives in SYS.%2DSUpdate discrete states SYS = X(n+1)% 3YRetur n outputs in SYS.% 4TNEXTReturn next time hit for variable step sample%time in SYS.% 5Reserved for future (root findin g).% 9Te

6、rmi natio n, perform any clea nup SYS=.% The state vectors, X and X0 con sists of con ti nu ous states followed% by discrete states.% Opti onal parameters, P1,.,P n can be provided to the S-function and% used duri ng any FLAG operati on.% When SFUNC is called with FLAG = 0, the followi ng in formati

7、o n% should be retur ned:% SYS(1) = Number of contin uous states.% SYS(2) = Number of discrete states.% SYS(3) = Number of outputs.% SYS(4) = Number of in puts.%Any of the first four eleme nts in SYS can be specified%as -1 in dicat ing that they are dyn amically sized. The%actual le ngth for all oth

8、er flags will be equal to the%len gth of the in put, U.% SYS(5) = Reserved for root finding. Must be zero.% SYS(6) = Direct feedthrough flag(仁yes, 0=n o). The s-fu ncti on%has direct feedthrough if U is used duri ng the FLAG=3%call. Setting this to 0 is akin to making a promise that%U will not be us

9、ed duri ng FLAG=3. If you break the promise%the n un predictable results will occur.% SYS(7) = Number of sample times. This is the nu mber of rows in TS.% X0= In itial state con diti ons or if no states.% STR = State orderi ng stri ngs which is gen erally specified as .% TS = An m-by-2 matrix containing the sample time%(period, offset) in formati on. Where m = nu mber of sample%times. The orderi ng of the sample times must be:%实用文案标准文档%TS = 00,: Continu ous sample time.%01,: Continu ous, but fixed in minor step%sample time.%PERIOD OF

温馨提示

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

评论

0/150

提交评论