1.4 Adding Rappture to MATLAB Applications

Video in TIB AV-Portal: 1.4 Adding Rappture to MATLAB Applications

Formal Metadata

1.4 Adding Rappture to MATLAB Applications
Title of Series
Part Number
Number of Parts
CC Attribution - NonCommercial - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this license.
Release Date

Content Metadata

Subject Area
00:09 Adding Rappture to MATLAB Applications 00:24 Example: Matlab/Octave Tool 02:06 What is the interface? 03:31 Build the interface: Temperature input 05:42 Build the interface: Ef input 06:29 Build the interface: Curve output 08:07 Build the interface: Use MATLAB/Octave 08:20 Add physics to the generated code 09:54 Add physics to the generated code 10:09 Running the code 10:55 Debugging 13:38 Assignment #4: Build a simple Spirograph tool
Simulation Interface (computing) Sheaf (mathematics) Bit Cartesian coordinate system Urinary bladder Value-added network
Greatest element Group action Drag (physics) Code Ferry Corsten Multiplication sign Plotter Direction (geometry) Execution unit Coroutine Sheaf (mathematics) Set (mathematics) Function (mathematics) Mereology Food energy Computer programming Formal language Electronvolt Different (Kate Ryan album) Computer configuration Core dump Moving average Data conversion Descriptive statistics Rhombus Area Source code Metropolitan area network Curve Physicalism Computer simulation Bit Maxima and minima Special unitary group Hecke operator Parsing Degree (graph theory) Type theory Order (biology) Quantum mechanics Interface (computing) output Website Right angle Energy level Quicksort Functional (mathematics) Game controller Statistics Regulärer Ausdruck <Textverarbeitung> Computer file Divisor Maxima and minima Online help Drop (liquid) Distance Computer icon Theory Value-added network Wave packet Number Revision control Goodness of fit Ring (mathematics) Energy level output Gamma function Default (computer science) Focus (optics) Standard deviation Distribution (mathematics) Interface (computing) Projective plane Plastikkarte Line (geometry) Directory service Cartesian coordinate system Graphical user interface Word Doubling the cube Personal digital assistant Function (mathematics) Physicist Universe (mathematics) Bijection Object (grammar) Maß <Mathematik>
Game controller Computer file Code Plotter Maxima and minima Set (mathematics) Device driver Function (mathematics) Mereology Computer programming Value-added network Formal language Mach's principle Duality (mathematics) Sic Core dump Moving average Energy level Information Descriptive statistics Scripting language Metropolitan area network Curve Sine Data storage device Code Physicalism Variable (mathematics) Rothe-Verfahren Substitute good Diameter Skeleton (computer programming) Arithmetic mean Vector space Personal digital assistant Octave Interface (computing) output Right angle Figurate number Resultant
Scripting language Point (geometry) Metropolitan area network Asynchronous Transfer Mode Computer file Information Maxima and minima Code Device driver Shape (magazine) Hand fan Inclusion map Type theory Radical (chemistry) Skeleton (computer programming) Deadlock Octave Figurate number Whiteboard Error message Freezing Asynchronous Transfer Mode
Point (geometry) Scripting language Curve Graph (mathematics) State of matter Code Cellular automaton Interface (computing) Real number Graph (mathematics) Spiral Expert system Function (mathematics) Number Graph theory Skeleton (computer programming) Type theory Personal digital assistant Integer Right angle Alpha (investment)
Scripting language Metropolitan area network Graph (mathematics) Insertion loss Code Plotter Spiral Maxima and minima Ext functor Line (geometry) Directory service Arm
Ocean current Game controller Multiplication sign Spiral Function (mathematics) Computer programming Value-added network Number Element (mathematics) Programmer (hardware) Medical imaging Cloning Descriptive statistics Metropolitan area network Default (computer science) Curve Touchscreen Graph (mathematics) Mathematical analysis Sound effect 3 (number) Binary file Cartesian coordinate system System call Quicksort Coefficient Freeware Resolvent formalism
Metropolitan area network Skeleton (computer programming) Computer file Octave Source code Gamma function Cartesian coordinate system Descriptive statistics Value-added network
Scripting language Metropolitan area network Email Computer file Code Statement (computer science) Maxima and minima Integrated development environment output Arithmetic progression Computer programming Number
Scripting language Metropolitan area network Data management Plotter Statement (computer science) Maxima and minima output Function (mathematics) Storage area network
Scripting language Metropolitan area network Computer icon Curve Default (computer science) Graph (mathematics) Interface (computing) Spiral Maxima and minima Computer simulation Menu (computing) Function (mathematics) Shape (magazine) Variable (mathematics) Computer programming Inclusion map Data management Uniformer Raum Vector space Different (Kate Ryan album) Complex number Personal digital assistant Integrated development environment Aerodynamics
all of a and it was hot only in simulation and will work for new technology Boardwalk ch this last
section now we're gonna put everything altogether is a little about about rapture you learn a little bit about Matlab now I'm going to show you how to build a Matlab application that has a rapture interface that trash that so
suppose you already have a Matlab program that somebody else wrote your advisor wrote would be surprised to be and you have a diamond file tomorrow and says here's the program put up on on right so that might write it like this if I had this very that amscript I could run Matlab national displayed as your fairy and it might do all that stuff remember I showed you few minutes ago that this function to display a prompt input all that stuff so that's what this program is going to do and it's gonna ask me to enter a Fermi level and I'm gonna type in 2 . 4 is going to tell me that the temperature and type in 77 and then it's going to run and when it's all done this program produces a file called out that that that has all this data so that's that's like the program that your advisor is going to give you were where you're you're seldom workers in the next cubicle that's the program may have and what you want to do is take that program and turn it into a rapture interface if we do it in rapture it'll look like this right instead of some 19 seventies looking thing like this will have a nice graphical interface with some input controls and some curves and you be able to plot multiple cases all that and by the way this example that we're we're walking through is actually in the rapture examples directory if you look in the the middle of in the rapture of the project and then all of you can find all these different examples in fact this this very example we do it all the languages so if you wanna see with the Fermi function looks in Python and how it looks in C language and for training and in this case we're looking at the version that's all in Matlab so the true so let's walk through it if you go into that directory and you take a look at the Fermi that amscript it looks like this this is a standard kind of matlab thing it starts out with a distance function in the input function because it's got you gotta get a value in for and then the destiny input function for the because you need a value for t and then at the end of it you can see the dust and stuff in the middle and at the bottom it opens up the file and writes out of my chest often in quick right so basically the top is words getting all the input values the bottom was worth writing out all the results and in between so there's a little bit of physics that just about any program that you look at you can kind of see that way so those 1st 2 lines of that number is next 2 lines of that number and this bottom part basically is sorta like the curve that you would get in rapture sites this sort of one-to-one correspondence that whenever I look at a program like this is always funny to me because usually about half the code the program is related to the inputs and the outputs right but people spend all the time trying to come up with fancy parser is although plotting routines and all that stuff which is great if you guys like to programming but if you just want to make a tool that works you really want focus all your effort on the middle part which is where the physics as so little bit code in the middle is where the action is and you can really help raptured take care of reviews rapture to take care of the rest of the stuff that trash alright so that's what we're gonna do
suppose we go into the rapture builder and we want to do the same thing that that instead of using input and output knowledge stuff will go into rapture and will grab a number of control of the left hand side drag and drop that the input section and if you look at the number we can give a label of ambient temperature we can get a nice description for the tool a default value member of everything shove a good default value on number control in rapture is like a double precision value so I can set 297 . 5 degrees Kelvin number also has units the units of measurement right there you can set the default units to be Calvin Fahrenheit centigrade whatever rapture smart about units it knows that Calvin fahrenheit and centigrade oral temperature so it knows how to do units conversions so you can say well I prefer kelvin but my user can type in whatever they want whatever their favorite units are and so we're gonna go and make held the standard units but again any temperature units will work and you can also set min max values on that so for example you guys know you might know from physics you can go below 0 degrees Kelvin 0 degrees Kelvin is absolute 0 it's the coldest possible temperature I don't know what happens I think that whole universe like rewinds if you go lower than 0 degrees Kelvin it's not allowed so and so we can't let our users simulate lower than 0 degrees Kelvin either because the simulator undoubtedly will caught so we can set a minimum value of 0 degrees Kelvin and and rapture will enforce that if someone tries to type a negative 5 rapture stops and right up front you can also set a maximum value 500 kelvins pretty hot and it's not a million degrees kelvin which is like the sun or something but it's pretty hot and there's a good chance that above 500 kelvin my simulators gonna caught up so I wanna make sure my simulated doesn't core dump all just put in a maximum 500 kelvin there but if there is no maximum for your simulated and don't specify max it so you don't have to have a minimax value those this help you god guard against that values so I can define a temperature that way that's 1 control I can define the next 1 the next 1 is my theory energy labeling very level that's what the physicists call it it's the energy at the center of the ferry distribution if you know what the heck that is of it's all the statistical probability quantum mechanics stuff but I give a good default value 0 electron volts and units in this case the units of energy electron volts or jewels are units of energy and rapture knows about both of them so offset EV is pretty good but most people are comfortable that set you use units of measurement and again I can send minimax value I could say really does make sense to go lower than 10 by extending the or higher than 10 dB but if it does make sense than just leave those are you know this is a few other options you can set an icon and this stuff like that if you wanna mess around with it can address up your interface the try last but not least I take the curve object and drag out over under the output side and then I specify everything I know about it so what is this curve the curve than producing is the Fermi-Dirac factor it's really great to give a good description to these things because when you're user hits the program but in like what the heck is the very direct factors like I can leave you guys come on that's not how many of you actually knew what the Fermi-Dirac factor was nobody right chanoyu you targeted now it's not just that it's after lunch and you shy about raising your hand because the act of course you don't know what the very direct factors at the very esoteric concept when you build tools everything you put in your tools can be confusing to some users because they haven't spent any time learning your area the stupid they don't know anything about this right so this very thing there even physicists out there I might use a different nomenclature you know I'm a for any function and they say which 1 very direct factor of order 1 apple what's right so you gotta be specific about this stuff so that people can understand what you're stimulating and what it means so you should always have some some pretty good descriptions of the goes along with all your all your people parts also we can specify the axes the X axis is going to be the Fermi function actually in the y axis here is energy as a little weird compared to most your x y plots but that's lamplighter here on the kind of tilted the way you might think about otherwise and you can specify descriptions of everything for the x and the y axis and you know it's units you know as my Y axis has units of electronvolts thing specify units all that so that all those to the plot try now on the
tools side there few more things to set remember the builder we always have the title and some description and then the language octave somebody's opted for this example right now
let's take a look remember when I say that of the builder is can automatically generate my skeleton file my mean diameter right if I take a look at the main died that got generated what I really wanna where says and your code here for the main by your program I wanna go back to that script I showed at the beginning I wanna take that chunk of code and stick it in there that's relevant so there is my chunk of physics code that's what I want to stick in the middle there and if you look at that physics code it's using variables called on and T. those are my inputs so if i'm clever about naming things they're figuring out how to get hooked up when I created the core control inside my fracture builder I call the temperature so temperature is is the same as what I was calling to in my other script f to kind of figure that out you know the variable that I'm calling in the builder versus what I'm calling in my code and make sure those are matched up and similarly on the output side my program produces vectors The N and down here the builder was calling X and Y so I don't match that of somehow got a set X equals B and y equals after I got a substitute enough in there or something that match that up to make it fit so if I take that code and stick it in the middle of my skeleton program and if I change of variable names to match 1 place to the other to make it all match up that everything all work so this is a way of doing it here I basically stuck the codon and I renamed to the T temperature and the 2nd half and on the x y data and everything else that fits everything else the work that to so now you remember how this works i've got a tool that XML and what I run rapture rapture reads the tool that XML and in this case creates the 2 inputs the temperature and the Fermi level and when I click on simulate it produces the driver files driver files copy of tool that XML but has the current values it runs my code which has the physics in there and then produces a run file on the run file has occurred in it and you can see all the x y values in the curve that's the data that I generate generated so that's how it works right that and then it plots then was that filed away and stores it in your results directly during the trash part
1 last thing I'll tell you before we get you go on your next lab assignment on the on every once in a while Matlab when it goes wrong because it does weird things on this goes wrong inside a script you might see it looking like hanging here and kind of freeze and you'll see something weird like the back shape and the greater the greater than or something weird like that but usually what happens Matlab at this point here there and is now waiting goes in the interactive mode is waiting for you to type something in raptures waiting for Matlab to finish and that I was waiting for you to type something right so you can get stuck in a deadlock so if you see something like this in running and it seems like it's taking forever it's like looks weird it could be that Matlab is kind of broken and waiting in this deadlock but I think activist slightly better behaved the other thing about Matlab is that sometimes it does weird things to terminal when this happens and then you go back to your X Germany tried type nothing types anymore your terminal that does screw things your terminal and so anyway be forewarned and if you see something weird like that you can click board and it may or may not give you some error information but anyway at that point you're going to have a driver file you can get in the matlab you can go through and run everything by hand like we're talking about earlier right so when you encounter an error which are likely to in Matlab script then you need to get in and try to run with the driver file by hand figure out what's wrong if you can get to run properly with the driver file just like this morning free then you go back to rapture and try every should work fine if you wanna run by hand we have a driver file so and make sure you say use rapture make sure you got use matlab reuse octave and then you can type in something like this you can type matlab that dashed are setting the variable in file equal to the driver file Common main this is sorta like the way Russia would run it if you looked inside the tool that XML or you can fire up matlab you can set the variable in file equals to the name of the driver file and indeed is run by and either way but what we're trying to do is we're trying to set the file equal to the driver file and then we're trying to run the script and so if you need to debug that's how you do it in an inactive you do something similar say octave and UNICEF in file to the driver files and can come from there that in file thing that I'm telling you about
if you look back in your script in this script near the top of his main that you'll see that it's looking for a variable called in file that's the name of the driver file so there's no magic you can look in the skeleton file and see that by so here is your next
lab assignment you guys are experts know inspire graph theory so you have the code for the spiral graph what we wanna do is we want to build a rapture interface for spiral graphs and this spiral graph is going to take 3 numbers and 1 and 2 and 3 use numbers not integers because you might want to take in a value like 13 point 2 in this case and it's actually allowed you can type in any real number but doesn't have to be an integer so you 3 numbers and then those of you in 1 and 2 and 3 and then at the end you're going to produce a curve for the alpha right so your 1st step is to get into the builder to put in 3 numbers and an output curve disabled is a tool that XML generate your main skeleton script and then you're going to go back to the cell is that when you're gonna state this code right in the middle of the cell script and if you do everything right it'll work like a dream to
private let me show you the solution now that I have for this assignment number 4 and we want to build a tool in rapture that takes this Matlab Octave code that were showing here and we want to build it into a tool with fracture where you can have a user specified inputs and generate the curves so folks
from show yeah here we are in the workspace and I can start up active and I can run my spiral graph script and it pops up a little plot and and I use these values for a and 1 and 2 and 3 if we look at the script again no big magic understanding and 1 and 2 and 3 and then using the 3 lines of code that I showed you for the lab exercise to do
the plot so the trick now is to take that script and convert it into a rapture tool so I'm going to make a directory on the x 4 and see that directory and then and the run the builder rapture dash builder and for this
particular tool it takes 3 numbers Simon drag the number control over 3 times for the 3 different numbers so takes the 3 numbers and 1 and 2 and 3 and then I'm going to produce a curve as the output result right so those are the things I need in rapture and I just checked fix up all the controls under renamed this number N 1 because that's the variable i wanna call in the Programme effect and even the label it 1 and I'll I'll call it 1st coefficient and I'll give a default value for example of 13 now go to the next number and all remaining at 2 n 2 and that the label on the screen also do and 2 I'll call it 2nd coefficient and see all of these guys OK and then later 6 and the 3rd element label and 3 colored 3 on the screen in that number and 3 that's the 3rd coefficient and given a default value of 0 6 I guess or something and then on the output side of call this 1 z and given label spiral graphs and Canada description for the axis label or call it real of z and if I scroll down there's also a Y axis label for image's z analysis take a look at the preview Previous says not dangers 5 warnings for the current tool definition examined resolve yes and what we through and show me everything I forgot or I should say that it's telling you should have a title for this tool so a call it's paragraph tool and I say next it tells me I description for the tool to yeah solution for OK for labs number 4 and then next and that tells me I have to choose the program but this is sort of a Matlab thing underneath the active and the new free clone of matlab instead alright so I fix those things a preview they're still 2 more
warning stop and I think they're just axis label warnings
yes it's bugging me about the x-axis description about the y axis description really I should fill those in and but I'll just flip to preview and ignore them
and looks pretty good overall so I'm gonna go and say this now given that the 2 warnings that's OK I'll say the tool that XML and also the skeleton program that I want generate an octave no need for a Makefile with active sources those 2 files from the builder now you can see I've got the 2
files now the trick is I go into the main program may not and this is generated by the rapture builder and I have these 3 numbers N 1 N 2 and N 3 and also up there and it says add your code here for the main body of the program so I'm going to go ahead and add that coding and from my previous scripts or get rid of these progress statements my program will take longer run and the loading and that Spiro . script that we're running just a minute ago right so that's the script that script had N 1 N 2 and N 3 hard-coded but now I'm going to get N 1 and N 2
and N 3 from rapture so I don't need those 3
statements of this delete those and fortunately I was smart enough to call my my rapture inputs and 1 and 2 and 3 so we're all we're all set to go there my script also had a plot statement and I don't need that and instead of a plot statement I'm going to do the
output thing in in rapture and you can see here there's this variable x y data composed of X and Y so really I just need to define what X and Y is minus x equals real of z and y equals the manager of z and then now I don't need the plot statement and everything connects up so that's pretty good now I've I've got my output here that's all connected up actually if I
didn't want those extra variables X and Y I could also just do this I could just say real of z like that and the manager of z like that I could plug those in right directly in place of X and Y and now I don't need those 2 vectors full shorter that way right so I've I've got my team i z that's basically the meet my program and then the z vector is being converted
into the real part and imaginary part which goes into the output curve but I wanna generate some that now and now if I run it in rapture will bring up the interface that I just created a lesson default values and I can click simulate and generate a case I can try something different minus 7 and simulate will generate another case and I can try to an 18 and minus 3 and set those values and simulate and I get yet another case so now I can use rapture to call my my program with all these different values getting kind interesting shapes along the way so now anyone can run my script and they can plug in lots of different values for spiral graph


  645 ms - page object


AV-Portal 3.20.2 (36f6df173ce4850b467c9cb7af359cf1cdaed247)