Simulink "MATLAB Function" block and extremum value

Hello. I am trying to use single input and single output Simulink matlab code function block: MATLAB function. I use the input value "u" to calculate the output value "y", which should be the maximum value of the function "factor (v, u)". The function "factor" depends on the Simulink block input "u" as well as the value which is needed to be found as output ("y" or "result" or "fcn(u)").
How could I find the maximum extremum value for the function factor(v,u) and which value for parameter "v" is needed to have the maximum value for factor (v, u) function? The result or output of the Simulink function block is the parameter value "v" which gives the maximum value for factor (v,u). How could I do it in correct way?
function y = fcn(u)
%function factor(v,u)
factor(v,u)=(18/(1/(u+0.01*v)-0.05/(v^3+1))-0.4*v-1)...
*exp(-2/(1/(u+0.01*v)-0.05/(v^4+1)))+0.8*u-6;
%end
fcn(u)=v=????....
result=fcn(v,u);
y = result;

Respuestas (1)

Note that there are a couple of important points here. (1) v input argument values have to be given/known to perform the calculations of your stated formulation. (2) therefore, there must be two input arguments to MATLAB fcn block. Considerign these two points ehre is the completed code of fcn:
function y = fcn(u, v)
H=(18/(1/(u+0.01*v)-0.05/(v^3+1))-0.4*v-1)...
*exp(-2/(1/(u+0.01*v)-0.05/(v^4+1)))+0.8*u-6;
[~, IDX] = max(H);
y = v(IDX);
One simple simulink model (Sim_Demo.slx) is attached to this post with this code.

5 comentarios

Anne
Anne el 29 de En. de 2023
Thanks for you help!
However, how can I give the value for v if the I don't know the value? In the Simulink model "sin" block was used, but it is not a correct way to define it. Do you just give a random value for v? What has to be the parameter "v" depence on "u" outside the matlab function block (in Simulink)?
Sulaymon Eshkabilov
Sulaymon Eshkabilov el 29 de En. de 2023
Editada: Sulaymon Eshkabilov el 29 de En. de 2023
This is a demo how one can employ MATLAB fcn block. You claim that v is defined via sin() function is not correct is inappropriate. Because v has to be defined with the given problem statement.
In this demo, for the sake of explanation, v is defined to be time dependent variable to show how two time dependent arguments u and v can be used for MATLAB fcn block.
Note that v can be also constant or result of another calculation within a model, and so forth.
if v is a constant then, it can be defined inside a fcn file without additional input variable.
Anne
Anne el 29 de En. de 2023
I understand the point. But I still not able to understand which would be best way to define in. Especially when it's dependence on the parameter "u" is that complex and cannot found that easily.
Check your problem statement carefully and then v can be defined. As of now, your problem is not explicitly defined for v. Your probelm description states some v variable which is not clear.
Or you are trying to solve/compute the formulation of H(u, v) for different values of v or what?
Anne
Anne el 29 de En. de 2023
I am trying to solve an equation for "v" which could give the maximum value for the function H(u, v) with given "u". So, basically in this matlabcode once the input value (u) is know because it is given to function block), I am trying to solve function H(u,v) to find max. H(u,v) and the value for parameter "v" (unknown in this case) that can give the maximum value for H(u,v). It is like an extremum problem for unknow "v" because "u" will be known once SImulink provides that value to the function block.

Iniciar sesión para comentar.

Categorías

Productos

Versión

R2022b

Preguntada:

el 29 de En. de 2023

Comentada:

el 29 de En. de 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by