Using Scilab, Get transfer function closed loop - pid

I have a XCOS scheme, where are presents:
My system G(Z)
A Pid controller
Now, I would like to know the closed loop transfer function.
How can i obtain it by scilab/Xcos ?
Thanks
Best
*** EDIT: ****
Following user1149326's suggestions :
loadXcosLibs(); loadScicos();
importXcosDiagram("/home/dursino/Desktop/nostro_sistema.xcos");
for i=1:length(scs_m.objs)
if typeof(scs_m.objs(i))=="Block" & scs_m.objs(i).gui=="SUPER_f" then
scs_m = scs_m.objs(i).model.rpar;
break;
end
end
-->sys = lincos(scs_m);
The last statement return this:
lincos: Unable to find diagram inputs
at line 118 of function lincos called by :
sys = lincos(scs_m);
Best regards

You can use lincos to create a linear state-space model from a general dynamical system described by a xcos diagram.
After obtaining the state-space model you can use ss2tf to convert it to a transfer function.

As mentioned by #spoorcc, you can use lincos to get the state-space representation of the system you made in Xcos. One important thing to remember is that you should use IN_f as the input and OUT_f as the output in Xcos. Only then you can get the state-space representation using lincos. I think you didn't use these in your Xcos model and that's why you got that error.
P.S. I know this answer probably won't help the OP (it's been 8 years now since it was asked) but I hope this might help someone like me who spent a lot on time searching for this method.

Related

How do you represent a function call as an if condition statement in Sequence Diagram?

I've been drawing a sequence diagram of a module recently, while reverse engineering.
I encountered a control statement, and it is like,
if (func_A() == True)
{
DoSomeThing();
}
else
{
DoSomeThingElse();
}
The problem is how to draw the condition?
As I mentioned, It is reverse engineering. The code cannot be modified now.
I drew two diagrams, and I don't know which way is right,
The first one is this, I think it's wrong because it doesn't show the function call as a message from A to B.
This is the second, It shows a message func_A.
What do you think about to do this right?
To complete the other answer there is anyway a problem in the second proposal because we do not know if in [func_A() == True] you reuse the value return by the previous call or you do a second call, to avoid that add the explicit return in your diagram :
Out of that do you know the activities ? A sequence diagram is "just" an interaction while an activity is a behavior and can be more adapted :
It depends. If func_A is an operation defined in Object2 the second representation would be correct. The first does not tell where the operation is defined. Most likely (!) one would interpret func_A as an operation local to ObjectA which your code seems to say. (Btw. you have two completely different object sets AB vs. 12 in your examples.) But that is uncertain. So the 2nd variant is more explicit (and correct).
In any case I advise to not overdo SDs with fragments as "graphical programming" doesn't make things easier to read (my practical experience). It's excellent to show message flows in various collaborations. But when it comes to conditions it's getting messy very soon. A better way is to create different sub-diagrams or even use pseudo code if there are too nested if conditions. In many cases such if clauses are a good fit for state machines.

How to insert print for each function of C language for debugging?

I am studying and debugging one software. There are thousands of functions in this software. I plan to add printf() at the entry and exit point of each function. It will take a lot of time.
Is there one tool/script to do this?
I may use '__cyg_profile_func_enter'. But it can only get address. But I have to run another script to get function name. I also hope to get value of input parameters of this function too.
You should give a try to AOP : Aspect Oriented Programming. Personnaly I've only tried with Java and Spring AOP but there's an API for C too : AspectC (https://sites.google.com/a/gapp.msrg.utoronto.ca/aspectc/home). From what I've seen, it's not the only one.
From what I've red about this library, you can add an pointcut before compiling with AspectC :
// before means it's a before function aspect
// call means it's processed when a function is called
// args(...) means it applies to any function with any arguments
// this->funcName is the name of the function handled by AspectC
before(): call(args(...)) {
printf("Entering %s\n", this->funcName);
}
(not tried by myself but extracted from the reference page https://sites.google.com/a/gapp.msrg.utoronto.ca/aspectc/tutorial)
This is only a basic overview of what can be done and you still have to deal with the compilation (documented in the page linked before) but it looks like it could possibly help you. Give a try with a simple POC maybe.

Using multiple assignment to do what array.insert does?

I'm going through the code on a sample solution to my first Ruby Quiz (The Solitaire Cipher), and ran across this little nugget:
def move_down( index )
if index == #deck.length - 1
#deck[1..1] = #deck[index], #deck[1]
#deck.pop
else
...
end
end
The person who wrote this solution apparently used the multiple assignment in the second line to insert #deck[index] into the position before #deck[1]. Why not just use this?
#deck.insert(1, #deck[index])
Is there a difference?
OK, now I see what you mean. Sure, they will give the same result. I guess it just would be matter of choosing which style is more clear for you, or how you think your code would be easier to understand and in consequence more maintainable.
If your question is about which method is more "performant" I don't know that answer and I don't think it evens matters, as ruby is not meant to be performant but to be expressive.

How to use arrays/lists and loops in Python

Ok so this is my first question here. I am currently an IT student and I am taking a fundamentals of programming class. I seem to be spending more time lost and confused than I feel as if I should. We are using Python as the programming language. The topic for this week is arrays and lists. From what I have gathered through reading many other forums, Python does not use array but lists. Therefore the assignment does not make since to me. Any help or guidance would be greatly appreciated.
Create a FLOWCHART and a STORYBOARD for each problem.
Use the information below to create a storyboard (which can be a text based description for solving the problems) and a flowchart (using flowchart symbols to illustrate how you would program) to solve each problem. You may use Microsoft Word® for your Storyboard and Microsoft PowerPoint® for your flowchart.
Problem 1: Create an array that contains the days of the week.
Problem 2: Create a loop to print the content above.
So what would the flowchart for this look like? The assignment next week builds on this by actually writing the program in Python. What would the script look like? Thanks for any help.
This is just for hinting, I won't write your program for you. In your comment, you assigned to the list (you're right, they're not called "arrays" in Python) correctly. Now you need to iterate over it to print each item individually. I'd suggest you refresh your memory in the Python Tutorial on how to control program flow, especially the for statement. Remember, the general idea is:
for item in collection_of_items:
do_something_with(item)
days = ['monday','tuesday','wednessday','thursday','friday','saturday','sunday']
for day in days:
print(day)
Edit:
what would the flowchart for this look like?
This problem is quite simple, try to make your own flowchart. Try to practice thinking at the very first lesson of programming course.
What would the script look like?
It would look like above code. But you can do it better and more professional, try to figure it out.

mvnpdf vs regular normal(gaussian) PDF - matlab / C

I'm performing gaussian mixture model classification, and based on that, used "mvnpdf" function in MATLAB.
As far as I know the function returns a multi variate probability density for the data points or elements passed to it.
However I'm trying to recreate it on C and I assumed that mvnpdf is the regular Gaussian distribution (clearly it is not) because the results don't match.
Does anyone know how "mvnpdf" works ? Because I haven't been able to find documentation on it .
The documentation for mvnpdf is here
if you are looking for the exact code just put a break point at the point where you call it and see how it works
Okay I actually found a decent link that explains in detail what's happening inside .
This might be a better link to look at - http://octave.sourceforge.net/statistics/function/mvnpdf.html

Resources