Automatically generate circuits on its own in PLECS (Piece-wise Linear Electrical Circuit Simulation ) - matlab

Is there any way I could program the Matlab/Simulink to be able to automatically generate circuits on its own? I am using PLECS blockset (Piece-wise Linear Electrical Circuit Simulation ) embedded in Simulink.
For example, I need to have hundreds of identical block in a single .mdl file, instead of inserting one by one by myself by calling the block which I previously saved in Simulink library, is it possible that Simulink can be programmed to automatically generate hundreds of blocks by itself?
The only way I was told is by "using vectorization for most components. Most components are vectorized if they have a vectorized input signal or if one of their parameter is specified as a vector." However, I could not find any further information/details, appreciate if anyone of you could give opinion on this?
I just want to know if this is possible? Else, I would have to try another approach?
Thanks!
edited on 10 July 2013: Further to my question, I have confirmed with Plexim that there isn't such features ( add_block and add_line) in Plecs (Piece-wise Linear Electrical Circuit Simulation), does anyone know if there is any way I could automate the Plecs model? Appreciate any suggestion...Thanks

You can probably use functions like add_block and add_line to automate the creation of your Simulink model from a library.

Related

Simscape, COMSOL compatibility in simulating electromagnetic range of inductive charging

I am currently trying to use Simscape to design and simulate the electrical circuit and COMSOL Multiphysics to simulate the electromagnetic interaction between coils. What I'm not certain of is whether or not we can successfully link the two software packages nicely via MATLAB or not. They both have MATLAB support though.
I am also researching whether ANSYS suite. There may be some software we can use that would take the place of one or both of the previous software.
Several years ago I had to make a connection between COMSOL and Matlab as well. This is called a Matlab Comsol LiveLink.
However, I think (not sure), that the electrical circuit should be modeled in COMSOL. Using the LiveLink you can set parameters in COMSOL using Matlab and extract the updated calculation. To my knowledge you cannot input a model, do calculations, and then extract the results.
You can look in the users guide, maybe it says something about this
Some other links which may be useful:
LiveLink™ for MATLAB®
Integrate COMSOL Multiphysics® with
MATLAB® Scripting

How to use Simlink PID tools to implement a controller in matlab

I was wondering if it is possible to use simlink's PID architecture in matlab to actually control hardware - rather than modelling it.
I have been playing around a little with the PID tuning in matlab - and have worked out the correct gains for my system (or at least good enough).
Now I want to implement the actual control loop in matlab using the real hardware. In this case I am tying to stabilise a laser using a measurement from a wavemeter - although from the point of view of matlab essentially I have two functions - one which returns the current wavelength, and another which alters the wavelength with an input from 0-100.
How do I get the fancy PID objects to work in a loop where for example I input data each loop, and get the required output to stabilise things given my gains - or should I just hardcode the equations in?
I have tried looking through some of the simlink examples - but there doesn't seem to me much actual implementation - mostly just modelling.
Thanks in advance for any advice.
MATLAB (without Simulink, or with Simulink in purely a simulation mode) is not a real-time environment. Trying to use it to control hardware in real-time won't work unless you have very slow sample rates.
If you do have slow sample rates, then you'd connect to your hardware to MATLAB using device drivers such as those in the Data Acquisition Toolbox
You haven't found any info on real-time implementation in the Simulink documentation because from Simulink the mechanism for real-time implementation is via Simulink Coder. You would need to use it in conjunction with a real-time environment such as Simulink Desktop Real-Time (if your sample rates are relatively slow), Simulink Real-Time, or one of many other 3rd party real-time form factors.

Generate equation from Simulink Model

I have a large simulink model with many source and sink blocks, many with only elementary arithmetic operations in between. I have been asked to document the equations behind the model. I am currently doing this manually and I am finding it rather slow and there is a relatively high chance of errors in the process.
Is there any way for Simulink to generate the equations (in MATLAB syntax for example) automatically?
There is no utility in MATLAB/Simulink that can do exactly what you are looking for (and I personally don't know of any third-party tools that can do this, either).
However, I think that your best bet might be to make use of Simulink Coder. This will allow you to convert your Simulink model to C code. From that code, you may be able to extract the equivalent equations more easily than you can by analyzing the Simulink model by hand.
The catch, though, is that Simulink Coder is an add-on package to base Simulink, so you may or may not have this tool available to you.

What's the difference between stateflow and simulink?

As far as I know, stateflow and simulink are often used at the same time, and are both environments developed by MathWorks, who make Matlab. May I know what's the difference between them?
Simulink is largely a controls oriented solution. It graphically depicts math like products, sums, integrals, etc. However, it's conditional logic facility is lacking. Any kind of if construct quickly becomes terse and unmanageable in my opinion. I've seen many models, and there is a clear line here where Simulink should end and Stateflow should start.
Stateflow deals extremely well with logic and, of course, state machines. Now with the addition of the Simulink Function blocks within Stateflow, we have a powerful combination to allow the state machine in Stateflow direct the rest of the program.
As far as functionality goes, they are both functionally complete, meaning anything you can code in C, you can code in Simulink or Stateflow. However, I would not recommend coding a PID loop in Stateflow, but it's possible. You could also easily create a state machine in Simulink, but I'd advise against it.
As far as code generation; in the beginning of the meld, the Stateflow and Simulink had separate code generators that were sewed together with more Simulink generated C code at code generation time. Then came CGIR (Code Generation Intermediary Representation), which unifies the code generator between Stateflow and Simulink. It came around 2007, and has continued to deliver substantial increases in performance. Generated code has increased in on target performance to a point where companies can use the code in their embedded systems and actually get a performance benefit rather than take a small hit. Also, the time to generate the code has also decreased substantially. CGIR is a replacement for the Target Language Compiler, however, never fear, TLC API will still be available, perhaps forever for those who have developed massive libraries of proprietary code generation libraries.
Hope this helps, let me know if something sounds fishy or if I need to clarify.
Quoting a Stateflow Webinar:
Simulink is used to respond to continuous changes in dynamic changes.
Stateflow is used to respond to instantaneous changes in dynamic changes.
Real-world systems have to respond to both continuous and instantaneous changes.
Use both Simulink and Stateflow so that you can use the right tool for the right job. Examples: Suspensions dynamics of a car are modelled with Simulink whereas, the gear transmission is modelled with Stateflow.
Learn more about Stateflow in general at:
http://www.mathworks.com/products/stateflow/examples.html
Stateflow has been updated for making it very easy to create state machines and flow charts in R2012b.
The major updates include a new graphical editor, state transition tables, MATLAB as the action language and an integrated debugger. Find short videos for these features and how they can be used at:
http://www.mathworks.com/products/stateflow/whatsnew.html
best,
Siddharth
I'm also currently involved with both simulink and stateflow. Till now I did everything in Simulink but once you have to implement logic( if, case) your model becomes visually difficult to be analysed after coding. But I think theoretically you can do everything also just in Simulink (correct me if I'm wrong).
The answer of macduff explains very good the differences.
Regards,
GR
I have worked on both on simulink and state flow environment both are Matlab tool. When u want to design a reactive system or event driven system at that time we should prefer stateflow instead of simulink.
because we can control an event in stateflow in better way compare to simulink .though debugging is easy in simulink but readability and code generation are easy in stateflow.
Complex state machine: Stateflow
Complex mathematical process: Simulink blocks
Others: both of Stateflow and Simulink are fine
Another major benefit of Stateflow is the integration and usage of external C code. This can be done by selecting the Action Language C within the Chart settings.
As commonly known the user can include external Code within the "Simulation Target" options. While a normal Simulink model need small workarounds to access the external C code (ceval(), Simulink.Parameter for globals etc.), Stateflow can directly access functions, defines, etc.
Problems like array of buses/structs can also be avoided by coding these arrays in external code.
For a lot of use cases I love the flexibility to directly interact with C code within Stateflow.

Simulink version of AnyLogic component

Does anybody know what components in Simulink (MATLAB package) are analogs for AnyLogic components? (e.g: source, buffer, delay, sink).
Or how can I easily simulate behavior of AnyLogic model in MATLAB?
Maybe there are some cool magic tools?
If you're asking whether or not there is an easy way to convert from an AnyLogic model to a Simulink model, I doubt it. I haven't seen any conversion tools like that.
I have a feeling you're just going to have to rebuild your AnyLogic model in Simulink if you want to simulate your models in MATLAB. I would start by looking through the Block List and Function List links on this Simulink documentation page. You should be able to find analogous components to those in your AnyLogic model.
AnyLogic is one of the best tools for business simulation and Matlab is the best engineering tool. But they have different notations.So in the most cases conversion is just impossible! E.g. to convert DE model of airport into Matlab.
My suggestion: use Matlab for engineering tasks and AnyLogic for business simulation.