下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、无自动化专业综合设计报告自动化专业综合设计报告设计题目:设计题目:利用利用 matlab 编写编写 S 函数求解微函数求解微分方程分方程所在实验室:所在实验室:自动化系统仿真实验室自动化系统仿真实验室指导教师:指导教师:郭卫平郭卫平学生姓名学生姓名律迪迪律迪迪班级班级文自文自 0921学号学号200990519114成绩评定:成绩评定:无一、一、设计目的设计目的了解使用 simulink 的扩展工具S-函数,s 函数可以利用 matlab 的丰富资源,而不仅仅局限于 simulink 提供的模块,而用 c 或 c+等语言写的 s 函数还可以实现对硬件端口的操作,还可以操作 windowsAPI
2、 等的, 它的魅力在于完美结合了 simulink 框图简洁明快的特点和编程灵活方便的优点,提供了增强和扩展 sinulink 能力的强大机制,同时也是使用 RTW 实现实时仿真的关键。二、二、设计要求设计要求求解解微分方程y=y-2x/yy(0)=1要求利用 matlab 编写 S 函数求解三、三、设计内容(可加附页)设计内容(可加附页)【步骤【步骤 1】获取状态空间表达式。】获取状态空间表达式。在 matlab 中输入dsolve(Dy=y-2*x/y,y(0)=1,x)得到y=(2*x+1).(1/2);【步骤【步骤 2】建立】建立 s 函数的函数的 m 文件。文件。利用 21用 S 函
3、数模板文件。以下是修改之后的模板文件 sfuntmpl.m 的内容。function sys,x0,str,ts = sfuntmpl(t,x,u,flag)%SFUNTMPL General M-file S-function template%With M-file S-functions, you can define you own ordinary differential%equations (ODEs), discrete system equations, and/or just about%any type of algorithm to be used within a S
4、imulink block diagram.%The general form of an M-File S-function syntax is:%SYS,X0,STR,TS = SFUNC(T,X,U,FLAG,P1,.,Pn)%What is returned by SFUNC at a given point in time, T, depends on the%value of the FLAG, the current state vector, X, and the current%input vector, U.%FLAGRESULTDESCRIPTION%-%0SIZES,X
5、0,STR,TSInitialization, return system sizes in SYS,%initial state in X0, state ordering strings无%in STR, and sample times in TS.%1DXReturn continuous state derivatives in SYS.%2DSUpdate discrete states SYS = X(n+1)%3YReturn outputs in SYS.%4TNEXTReturn next time hit for variable step sample%time in
6、SYS.%5Reserved for future (root finding).%9Termination, perform any cleanup SYS=.%The state vectors, X and X0 consists of continuous states followed%by discrete states.%Optional parameters, P1,.,Pn can be provided to the S-function and%used during any FLAG operation.%When SFUNC is called with FLAG =
7、 0, the following information%should be returned:%SYS(1) = Number of continuous states.%SYS(2) = Number of discrete states.%SYS(3) = Number of outputs.%SYS(4) = Number of inputs.%Any of the first four elements in SYS can be specified%as -1 indicating that they are dynamically sized. The%actual lengt
8、h for all other flags will be equal to the%length of the input, U.%SYS(5) = Reserved for root finding. Must be zero.%SYS(6) = Direct feedthrough flag (1=yes, 0=no). The s-function%has direct feedthrough if U is used during the FLAG=3%call. Setting this to 0 is akin to making a promise that%U will no
9、t be used during FLAG=3. If you break the promise%then unpredictable results will occur.%SYS(7) = Number of sample times. This is the number of rows in TS.%X0= Initial state conditions or if no states.%STR= State ordering strings which is generally specified as .%TS=An m-by-2 matrix containing the s
10、ample time%(period, offset) information. Where m = number of sample%times. The ordering of the sample times must be:%无%TS = 00,: Continuous sample time.%01,: Continuous, but fixed in minor step%sample time.%PERIOD OFFSET, : Discrete sample time where%PERIOD 0 & OFFSET PERIOD.%-20;: Variable step
11、 discrete sample time%where FLAG=4 is used to get time of%next hit.%There can be more than one sample time providing%they are ordered such that they are monotonically%increasing. Only the needed sample times should be%specified in TS. When specifying than one%sample time, you must check for sample h
12、its explicitly by%seeing if%abs(round(T-OFFSET)/PERIOD) - (T-OFFSET)/PERIOD)%is within a specified tolerance, generally 1e-8. This%tolerance is dependent upon your models sampling times%and simulation time.%You can also specify that the sample time of the S-function%is inherited from the driving blo
13、ck. For functions which%change during minor steps, this is done by%specifying SYS(7) = 1 and TS = -1 0. For functions which%are held during minor steps, this is done by specifying%SYS(7) = 1 and TS = -1 1.%Copyright 1990-2002 The MathWorks, Inc.%$Revision: 1.18 $% The following outlines the general
14、structure of an S-function.%switch flag,% Initialization %case 0,sys,x0,str,ts=mdlInitializeSizes;% Derivatives %无case 1,sys=mdlDerivatives(t,x,u);% Update %case 2,3,9,sys=;% Outputs % GetTimeOfNextVarHit % Terminate % Unexpected flags %otherwiseerror(Unhandled flag = ,num2str(flag);end% end sfuntmp
15、l%=% mdlInitializeSizes% Return the sizes, initial conditions, and sample times for the S-function.%=%function sys,x0,str,ts=mdlInitializeSizes%无% call simsizes for a sizes structure, fill it in and convert it to a% sizes array.% Note that in this example, the values are hard coded.This is not a% re
16、commended practice as the characteristics of the block are typically% defined by the S-function parameters.%sizes = simsizes;sizes.NumContStates= 1;sizes.NumDiscStates= 0;sizes.NumOutputs= 0;sizes.NumInputs= 0;sizes.DirFeedthrough = 1;sizes.NumSampleTimes = 1;% at least one sample time is neededsys
17、= simsizes(sizes);% initialize the initial conditions%x0= 0 1.0000;% str is always an empty matrix%str = ;% initialize the array of sample times%ts= 0 0;% end mdlInitializeSizes%=% mdlDerivatives% Return the derivatives for the continuous states.%=%function sys=mdlDerivatives(t,x,u)无sys(1)=(u-2*x/u)
18、*t+u;【步骤【步骤 3】利用】利用 matlab 调用函数得到结果。调用函数得到结果。利用 sys=sfuntmpl(,x,1)调用 S 函数,替换 x 得到不同的结果四、四、设计实验结果及分析设计实验结果及分析替换不同德 x 得到不同结果。为检验结果是否正确在命令窗口运行x1(1)=0;y1(1)=1; h=0.1;for k=1:10 x1(k+1)=x1(k)+h;endx=0:0.1:1;y=(2*x+1).(1/2);x1=x1(1:11),y=y(1:11),无与 S 函数所对应,所以上述实验结果正确。五、五、结论结论上述为本次解微分方程得到的结果。六、六、设计感受设计感受通过本次试验充分理解了 S 函数的框图简洁明快的特点和编程灵活方便的优点。同时复习总结了 matlab 程序的使用。实验过程遇到得问题通过咨询老师,同学讨论,查阅资料的都得到了解决,充分锻炼了自己认识问题解
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 家电厂设备维护细则
- 踝关节韧带损伤治疗
- 自闭症康复实习心得
- 根管再治疗术
- 重症医学科护理管理品管圈
- 2027年阿克苏职业技术学院单招综合素质考试题库及答案1套
- 2026马达加斯加旅游服务业市场现状与投资潜力深度分析发展研究报告
- 2026中国污水处理行业技术升级与投资回报分析报告
- 2026中国石油天然气行业市场深度调研及发展前景与投资前景研究报告
- 2026中国智能脑电图仪行业市场供需分析及投资评估规划分析研究报告
- T/CCOA 59-2023粉末油脂
- 第四届福建省水产技术推广职业技能竞赛-水生物病害防治员备赛题库(含答案)
- 五人合伙协议样本
- 合伙人协议合同
- 2024年银行外汇业务知识理论考试题库及答案(含各题型)
- 集成电路封装材料-芯片黏接材料
- 国民经济行业分类代码表
- 垃圾分类知识科普
- 历代公文选第一章-公文概说资料课件
- 美国专利法及实务培训-上传课件
- 技术的本质(经典版)
评论
0/150
提交评论