Langsung ke konten utama

The MATLAB Function Block

In addition to reading and creating MATLAB variables, Simulink can utilize MATLAB functions. Simulink blocks perform a specific operation on inputs and return outputs. This is analogous to a function in text-based code. The MATLAB Function block (Simulink > User-Defined functions) allows you to incorporate a MATLAB function directly into your model.




Double-clicking on the MATLAB Function block opens a MATLAB Editor:


The input, 
u
, and the output, 
y
, of the function are mapped to the input and output, respectively, of the block. Adding additional inputs or outputs will change the number of ports on the block:

The MATLAB Function block is useful when incorporating existing MATLAB code and when modeling complicated algorithms.


Task 1
In this lesson, you will model the power output from a tidal turbine over the course of several hours. The equation for this is

Power=12CpρA(2g|ΔH|)3/2
.
The Sine Wave block in the model represents the height differential, 
ΔH
, of the water on different sides of the turbine.

TASK
The MATLAB Function block has been pre-populated with the values of the constants. Double click on the block to open the MATLAB editor, and then add the equation such that 
ΔH
 is the input, and turbine power is the output.



Komentar