Example: bachelor of science

7 Getting Started - Scicos

A SimpleDiagramScicoscontainsa graphicaleditorthatcanbe usedto constructblock cancomefromvariouspalettesprovidedin Scicosor canbe user-de thissection,we describe how theeditorcanbe usedto constructsimplemodelsandhow thesemodelscanbe a Scilabtoolbox includedin openedby thescicoscommand7 ! Scicos ;Thiscommandopensupanempty Scicosdiagramnamedby defaultUntitled. Calledwithanargument, it canopenupanexistingdiagram:7 ! ;TheScicosmainwindow displayinganempty diagramis illustratedin Thelookof themainwindow may be slightlydi erent underdi erent window thetopof each functionality is displayedbyselectingHelpin theMiscmenu andthentheitemof interestin theeditorfunctionalitiescanalsobe accessedby clickingtheright , keyboardshortcutscanbe example,typingan\r"activatestheoperation Replot, which de nedby ModelTo constructa model,we needto elementaryblocks organizedin di erent palettesthatcanbe accessedusingtheoperationPalettesin theEditmenu.

7 Getting Started 7.1 Construction of a Simple Diagram Scicos contains a graphical editor that can be used to construct block diagram models of dynamical systems.

Tags:

  Getting, Started, 7 getting started

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of 7 Getting Started - Scicos

1 A SimpleDiagramScicoscontainsa graphicaleditorthatcanbe usedto constructblock cancomefromvariouspalettesprovidedin Scicosor canbe user-de thissection,we describe how theeditorcanbe usedto constructsimplemodelsandhow thesemodelscanbe a Scilabtoolbox includedin openedby thescicoscommand7 ! Scicos ;Thiscommandopensupanempty Scicosdiagramnamedby defaultUntitled. Calledwithanargument, it canopenupanexistingdiagram:7 ! ;TheScicosmainwindow displayinganempty diagramis illustratedin Thelookof themainwindow may be slightlydi erent underdi erent window thetopof each functionality is displayedbyselectingHelpin theMiscmenu andthentheitemof interestin theeditorfunctionalitiescanalsobe accessedby clickingtheright , keyboardshortcutscanbe example,typingan\r"activatestheoperation Replot, which de nedby ModelTo constructa model,we needto elementaryblocks organizedin di erent palettesthatcanbe accessedusingtheoperationPalettesin theEditmenu.

2 Thisoperationopensupa dialogbox thatincludesthelistof palettein thelist,a newScicoswindow opensupdisplayingtheblocks availablein in copiedinto themainScicoswindow by clicking rstonthedesiredblock andthenat thelocationwheretheblock is to be copiedin wavegeneratorsquare wavegeneratorrandomgeneratorrandominput fileread frominput fileread from1111sound fileread from .ausound fileread from .augeneratorsawtoothgeneratorsawtoothgen eratorsinusoidgeneratorsinusoid11C binary fileread fromC binary fileread fromModulo 3 CounterModulo 3 in inputsandblocks withoutany outputssuch as scopes andright-to- startby copyingfromthesepalettesthreeblocks as illustratedin In this gurewehave copieda sinusoidsignalgenerator,a scope, andanevent generator(EventClock).The rstblock generateson itsuniqueoutputporta wishto display thissignalusingthescope.

3 Thiscanbe doneby connectingtheoutputof thesignalgeneratorto theinputof thescope by clicking rstontheoutputportandthenneartheinputpor tof thescope. TheAlignoperationin theEditmenu canbe usedto alignthetwo portsbeforehandin orderto make a usedtoactivatethescope block periodicallywiththedesiredfrequency. Everytimethescope is activated,it readsthevalueof thesignalonitsinputport(which is nothingbutthevalueof sin(t) generatedby thesignalgenerator).Thisvalueis thenusedto constructthecurve thatis displayed in thescope window. To specifythatthescope block is activatedby theevent generator,theactivationoutputof theeventgeneratorshouldbe connectedto theactivationinputof thescope. Theresultthenlookslike thediagramin Thisdiagramis now di erent types of ,theactivationlinksaredrawnin redandtheregularlinksin black, butthiscanbe theblocks whereasactiva-tioninputsandoutputsareres pectivelyonthetopandat thebottomof thisconvention,buttheusercande ,throughpull-downmenus,many functionalitiesto changethelookof thediagramandthatof theblocks such as changingcolor,size, simulatea diagram,it su cesto setby theSetupoperationin thesamemenu.

4 Therewecan,forexample,adjustthe theopeningof a graphicswindow andthedisplay of a is openedandupdatedby the1667 GettingStartedscope block. Thesimulationresultis given in In thiscase,the nalsimulationtimeis setto the nalsimulationtimeis simulationcanbe stoppedusingthestopbuttononthemainScicos window,subsequent to whichtheuserhastheoptionof continuingthesimulation,endingthesimulat ion,or 10 50510+ window forthesystemin Scicosdiagramcanbe modi thediagramin illustratedin Theintegratorblockgives as anoutputtheintegralof alsoreplacethescope witha multi-inputscope. Notethatto createa splitona link,in particularhereto createa linkgoingto theintegrator,o thelinkconnectingthesignalgeneratorto thescope, theusermustclick rstontheexistinglinkat thepositionwherethesplitis to be createa brokenlink,theusercanclick onintermediarypoints beforeclickingonthedestination,which is givenin ParametersThebehaviorof a Scicosblock may dependonparametersthatcanbe modi edby changedby clickingontheblock.

5 Thisactionopensupadialogbox showingcurrent valuesof theblock parametersandallowingtheuserto example,thedialogbox associatedwiththeintegratorblock is Theotherblocks alsohave example,in thesinusoidgenerator,we cansetthefrequency, theamplitude, thesameway, certainpropertiesof thescope window canbe setby theparametersof thescope a parametercanbe de nedby any example,thefrequencyof thesinusoidgeneratorcanbe setto2*%pi/10. TheScilabinstructioncanalsoincludeScilab variables,butthesevariablesmusthave beenpreviouslyde a SimpleDiagram167generatorsinusoidgenerat orsinusoid1 +036912151821242730 + window aftersimulationof themodi the\context"of variablesarecalledsymbolic parameters. Symbolicparametersandthecontextwillbe discussedin now considermorecomplicatedexamplesin which thesystemswe want to modelaregivenby di is usedto de neeach stateof Model for Spread of DiseaseWe considera simplemodelof how a diseasecanspreadin a community [5].

6 Lets(t) bethefractionof thepopulationsusceptibleto gettinginfectedas a functionof timet. Alsoleti(t) be theinfected(andinfectious)fractionof thepopulationandr(t) therecovered,andthusimmune,fractionof expressedasfollows:1687 of as(t)i(t);( )_i=as(t)i(t) bi(t);( )_r=bi(t);( )whereaandbarepositive modelthissystemin Scicos ,we setthestateof oneintegratortos, anotheronetoi, anda thirdonetor. It is thenstraightforwardto constructtheinputsof theintegratorsfromtheiroutputs,as canbe seenin Herewe have setato 1 andbto 0 thereaderlessfamiliarwithblock diagrams,the and blocks multiplyandaddinputsrespectively. Sincewe arecallingtheoutputsof theintegratorblockss,i, andr,theScicosimplementationof thedi erentialequationin ( ) canbe thought of as theintegralequations(t) = Ztt0s( )i( )d +s(t0);wheres(t0) is theinitialconditionofsat timet0. Similarly( ), ( ) areimplementedas integralequationsin ,theyareintegratedas di erentialequationsby Scicosusinga givenin Thevariablesisinitializedto 0:999,andito 0 a R osslerAttractorTheR osslersystem[35] given below haschaoticbehaviorforcertainvaluesof theparam-etersa,bandc:_x= (y+z);_y=x+ay;_z=b+z(x c):Thissystemis modeledin 0:2 andc= 5:7.

7 Theinitialconditionsaresetto is usedto plotyagainstx. Theresultis given in 1 + ,as expected,thatthepercentageof therecoveredpopulationis increasingandthatof thesusceptiblepopulationis populationinfectedreachesitsmaximumat a timecalledthepeakof is usefulto usesymbolicparametersto de neblock partic-ularlythecaseif thesameparameteris usedin morethanoneblock or if theparameteris computedas a functionof de nedin thecontextof thediagrambeforebeingusedin thede nitionof block Scicosdiagramcontainsa simplya Scilabscriptusedto de neScilabvariables,which canthenbe usedto de neblock accessthecontextof thediagram,usetheContextbuttonin theEditmenu. Thisopensup1707 GettingStartedYXZ ++++. +++++ + theR osslerattractor. 15 12 9 6 303691215 15 12 9 6 303691215+ the2 Dscope fortheR writea Scilabscript,thatis,a setof Scilabcommandsthatareexecutedby Scilabaftera click example,if thecommandC=1is placedin thecontext,thenCcanbe usedto de nea block thevalueofCis changedin thecontext,theparameterof theblock is now consideran examplein which thecontextis veryusefulforde ninga considertheconstructionof a sampled-dataobserver fora consideredto be modeledas a continuous-timestate-spacelinearsystem:_ x=Ax+Bu;( )y=Cx;( )whereA,B,Careconstant developingcontrolsfora systemlike this,it is ofteneasierto developthemin termsof thestatex.

8 Statefeedback beavailablein practiceis theoutputy. A stateobserver is anotherdynamicalsystem,whichacceptsas inputuandy, andgives as anoutput^x, which hastheproperty thatx ^xgoes to zeroindependent of theinitialconditionsof either( ) or theniceproperty of beingableto returnto givinggood theerrorgoes to zerocanbe speci edto give good estimationbutavoidbeingoverlysensitive to continuous-timeobserver canbe constructedas follows:_^x=A^x+Bu+K(y C^x):( )ThematrixKmustbe chosenso thattheeigenvaluesofA KChave negative ~x= ^x xsatisfying_~x= (A KC)~xwillgo to (sampleddata)observer is obtainedby rstconstructingthecor-respondingcontinuo us-timeobserver usingthemethod of poleplacement, andthendis-cretizingit. We beginby taking to make thisa performthisprocedurewithrandommatrices,p lacedin thecontextof thediagram,is thefollowing:n=5;m=2;dt=.2;A=rand(n,n);A =A-max(real(spec(A)))*eye()B=rand(n,1);C =rand(m,n);D=zeros(m,1);x0=rand(n,1);K=p pol(A',C',-ones(x0))';Ctr=syslin('c',A-K *C,[B,K],eye(A),zeros([B,K]))Ctrd=dscr(C tr,dt)[Ad,Bd,Cd,Dd]=abcd(Ctrd)Theorigina lsystemis constructedwithrandommatrices,andtheAmat rixis mod-i edto make surethesystemis (eigenvalueassignment) functionppolis usedto obtaintheobserver gainmatrixK, anddscris usedto usedto simulatetheobserver setto sin(t) andtheestimationerroris displayed usinga scope.

9 The rstaresetas illustratedin in The rstblock alsooutputsitsinternalstateto be used1727 GettingStartedgeneratorsinusoidgenerator sinusoidy=Cx+Duxd=Ax+Buy=Cx+Duxd=Ax+BuDe muxy=Cx+Dux+=Ax+Buy=Cx+Dux+=Ax+BuMux+ + of theblock realizingtheoriginalsystem;theoutputof of by usedto de netheperiodof symbolicparametersis particularlyusefulin thiscasebecauseit allowsus to constructa genericsystemobserver changethesystemmatricesA,B,andC, thesizeof thesystem,thesizeof theoutputs,or thediscretizationtime,we onlyhave to modifythede nitionof them,n, madeto fact,by rewritingthecontextas followswe canmake thediagramcompletelygeneric:load('datafi le')K=ppol(A',C',-ones(x0))';Ctr=syslin( 'c',A-K*C,[B,K],eye(A),zeros([B,K]))Ctrd =dscr(Ctr,dt)[Ad,Bd,Cd,Dd]=abcd(Ctrd)We justhave to make surethatthedata ledatafilecontainsvariablesA,B,C,D,x0, lecanbe createdin Scilabas follows:7 !

10 Save('datafile'',A,B,C,x0,dt)RemarkIf thecontextcontainsmany linesof Scilabcode,it is convenient to placethecodein aseparatescript leandexecuteit witha singleexeccommandin ,if the lebeingexecutedby theexeccommandis changedwhenthediagramis alreadyopen,andtheuserwants themodi cationto be takeninto account, heor sheshoulddoanEvalbecauseScicoshasnoway of knowingwhetherthe shouldalsobe notedthatusinga separatescript leimpliesthattheScicosdiagramis notself-containedandthisscript lemustalways accompany is notgood modelingpracticeto placetoo many blocks in a diagramat thesamelevelbecausethediagrambecomesinco mprehensibleanddi cultto largesystems,it is usefulto usetheSuper block facility to constructa block lookslike any otherblock: it canbe moved,copied,resized,etc.,butitsbehavior is de nedby Super Block in a DiagramTherearetwo ways to placea Super block in a thesubmodeltheuserwants to placein a Super block alreadyexistsin themodel,thentheRegion-to-Super-blockope rationof theDiagrammenu canbe usedto placeit in aSuper block.


Related search queries