230 likes | 356 Views
EET 2259 Unit 10 Clusters and Matrices. Read Bishop, Sections 6.4 to 6.10. Lab #10 and Homework #10 due next week. Exam #2 next week. Polymorphism. Polymorphism is a feature of functions in modern programming languages such as LabVIEW.
E N D
EET 2259 Unit 10Clusters and Matrices • Read Bishop, Sections 6.4 to 6.10. • Lab #10 and Homework #10 due next week. • Exam #2 next week.
Polymorphism • Polymorphism is a feature of functions in modern programming languages such as LabVIEW. • It lets a single function work on inputs of different dimensions and data types. • This allows one function to do the work that you’d need several different functions to do in older languages that don’t have polymorphism. (Bishop, p. 310)
Polymorphism Example: Add • LabVIEW’s Add function is an example of a polymorphic function. • It can add a scalar plus a scalar, or an array plus an array, or a scalar plus an array. • In non-polymorphic languages, this would require several different functions.
Clusters • Recall that an array is a variable-sized collection of elements that are all of the same data type (such as numeric, string, or Boolean). • In contrast, a cluster is a fixed-sized collection of elements of mixed data types. • While a cluster can group different types of controls or different types of indicators, it cannot group controls together with indicators. (Bishop, p. 313)
Usefulness of Clusters • Clusters are useful when you have a related group of elements of different data types that you want to associate with each other. • Example: you might group a string containing a person’s name together with an integer containing his/her age and a Boolean indicating his/her citizenship status. • Clusters often let you simplify block diagrams by reducing the number of wires on the diagram. (Bishop, p. 314)
Creating a Cluster of Controls or Indicators • To create a cluster of controls or indicators: • Place a cluster shell on the front panel from the Controls >> Modern >> Array, Matrix & Cluster palette. • Place controls or indicators inside that cluster shell. (Bishop, pp. 314-315)
Brown or Pink? • On the block diagram, cluster terminals and cluster wires are colored brown if all of the items in the cluster are numeric. • But the terminals and wires are colored pink if one or more of the items are non-numeric.
Order within a Cluster • Individual items within a cluster are referred to by the order in which they were placed in the cluster. • The first item placed in a cluster becomes element 0, the next item placed in the cluster becomes element 1, and so on. • To change the order, right-click a cluster’s border on the front panel and select Reorder Controls in Cluster. (Bishop, p. 316)
Connecting Control Cluster to Indicator Cluster • You can wire a control cluster to an indicator cluster if they contain the same number of elements and if the data types of the corresponding elements match. • Example: if a control cluster’s element 0 is a string control and its element 1 is a numeric control, you could not wire it to an indicator cluster whose element 0 is a numeric indicator and whose element 1 is a string indicator. (Bishop, p. 317)
Cluster Functions • LabVIEW provides several functions for working with clusters, including: • Unbundle • Unbundle By Name • Bundle • Bundle By Name • These and others are on the Functions >> Programming >> Cluster & Variant palette. (Bishop, p. 319)
Unbundle and Unbundle By Name • The Unbundle and Unbundle By Name functions are used to split a cluster into its individual objects. (Bishop, p. 323) • Recommendation: Use Unbundle By Name instead of Unbundle.
Bundle and Bundle By Name • The Bundle and Bundle By Name functions are used to replace objects in an existing cluster, or to assemble objects into a new cluster. (Bishop, p. 319) • Recommendation: Use Bundle By Name instead of Bundle.
Cluster Example: Displaying Multiple Plots on a Chart • Many LabVIEW indicators and functions have input terminals that can accept clusters. • Example: To display more than one plot on a waveform chart, bundle the data together using the Bundle function. (We’ll discuss charts in more detail next week.) (Bishop, p. 351)
Matrices • A matrix is a two-dimensional array of numbers. (And a vector is a one-dimensional array of numbers.) • The branch of math called linear algebra studies rules and techniques for manipulating matrices and vectors. • Scientists and engineers use matrices and vectors to solve many types of problems.
Matrices in LabVIEW • LabVIEW has a matrixdatatype that is basically a special case of the array datatype. • A matrix must be two-dimensional, and it can only hold numbers (real or complex). • LabVIEW does not have a special vectordatatype: just use a 1-D array.
LabVIEW Matrix Functions • LabVIEW has a large collection of powerful functions that work on matrices and vectors. • See the Programming > Array > Matrix palette and the Mathematics > Linear Algebra palette.
Solving Systems of Linear Equations • As a simple example, matrices can be used to solve systems of linear equations, which arise in many applications. • Applications include the circuit-analysis techniques called mesh analysis and nodal analysis that you studied in DC Circuits (EET 1150). • Suppose we want to find the currents in the circuit on the next slide….
Mesh Analysis • Mesh analysis (also called “loop analysis”) involves three steps: • Apply Kirchhoff’s Voltage Law (KVL) around each loop to set up a system of linear equations. LabVIEW can’t help with this step; you have to do it by hand. • Solve the system of linear equations. Doing this by hand can be very tedious, but with LabVIEW it’s very easy. • Interpret the results of Step 2.
Step 1. Applying KVL • In our circuit, applyingKVL to the three loops gives us the following system of equations:
Step 3. Interpreting the Results • To interpret the results we must recognize that in the original circuit, • This gives us the current through each resistor.