Matlab function for RLC circuit in simulink
11 views (last 30 days)
Show older comments
I am using the attached code to simply apply Ohm's law using simulink. I have avariable resister (Let us assume it, R=A/B). I used matlab function to calculate the value of R. Unfortunately, Simulink can't identify the value of R ! it says: "Undefined function or variable 'R' ".
Any hint is highly appreciated,
Aalim
2 Comments
Answers (1)
Walter Roberson
on 26 Jul 2019
You have a subsystem named R_acd .
Inside that, you have a MATLAB Function Block that accepts w_AI2O3 and T as inputs and calculates k. That code ignores that input T and assigns 950 as T.
The flow out of the MATLAB Function block looks like it passes k to another MATLAB Function Block that is confusingly also named R_acd . That MATLAB Function block accepts no inputs (and if you look the connection between k from the other block and the R_acd block is dashed red indicating no signal flow). The function block internally defines a series of variables with constant values and calculates output R_acd . The function is also responsible for creating an output named k but it never assigns anything to k even though it uses k in the calculation.
The subsystem also accepts an input from a GOTO and passes it to a Physical Modeling Component confusingly also named R_acd . That component is defined as calculating resistance by the formula
(L-Bb)/(S*k)+(Bb-Db)/(S*k*(1-2*w_AI2O3)^1.5)
. However, variables L, Bd, S, and Db do not exist anywhere in the model. Variables k and w_AI2O3 do exist at points in the model, but it is not immediately clear that those exist at that particular level.
Now, your MATLAB Function Blocks assign to some of those values. You need to understand that unless you make special arrangements, any variable you assign to inside a MATLAB Function Block that is not an output, is treated as a local variable -- so for example although you assign to the variable L in some of those MATLAB Function Blocks, that that assignment will not carry through to the
(L-Bb)/(S*k)+(Bb-Db)/(S*k*(1-2*w_AI2O3)^1.5)
formula. Furthermore, there is nothing enforcing that the R_adc MATLAB Function Block would be executed before the PMComponent block.
- You should be making sure that your inputs are carried through properly, output at appropriate places and input at appropriate places
- You should ensure that you assign values to all of the outputs in your MATLAB Function Blocks
- You should use a better naming scheme to avoid the confusion about using the same name for multiple kinds of items
- You should investigate Constant Blocks
- You might need to route constants in as signals
4 Comments
Walter Roberson
on 26 Jul 2019
Edited: Walter Roberson
on 26 Jul 2019
Just having a port named R on your function block does not mean that there is a variable named R in the model that can serve as the source for the value of the resistor for the Series RLC Branch.
On the Controlled Current Source, the + and the - are both outputs, but your connections suggest that you are trying to use the + as the input to the resistor and that you are sending to the output of the resistor to the - side of the Controlled Current Source, as-if it were an input there instead of an output.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!