Simulink --- Peacewise Defined Function
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
I´m using "S-function" block in simulink to create a peacewise defined function.
if true
% code
void test_Outputs_wrapper(const real_T *x,
real_T *y)
{
// if(*x==0){ //x=0 Undefined
// y[0]=-0.00001;
// }
// else if(*x==1) //x=1 Undefined
// {
// y[0]=1.00001;
// }
// else
// y[0]=1/((x[0]*x[0])-x[0]); //y = 1/(x^2 -x)
y[0]=1/((x[0]*x[0])-x[0]);
} end
The function above (inside the TAG CODE is: y = 1/(x^2 -x) ) I´m using a Signal Builder (block) where I set a ramp from 2 to 10 (y values).
Setting the domain out of a Undefined values for x a peace of a function run right.
When I use a code below, trying to define x values where a function is Undefined it goes wrong.
if true
% code
void test_Outputs_wrapper(const real_T *x,
real_T *y)
{
if(*x==0){
y[0]=-0.00001;
}
else if(*x==1)
{
y[0]=1.00001;
}
else
y[0]=1/((x[0]*x[0])-x[0]);
} end
Range between 0 and 10 (Signal Builder)
Then a got the graph below:
How can I define it using S-function?
If there is a best way to do that I will be apreciated to know.
Thanks in advance.
0 Commenti
Risposte (2)
Birdman
il 16 Gen 2018
Hi Mario,
Firstly, I want to say that you can easily implement what you want by not using S-function. It will be easier. I suggest you to implement it in a MATLAB Function block where you basically write a simple function which consists of if-elseif. The problem you encounter has something to do with your solver type. Probably it is set to variable-step solver and it automatically adjusts the step size necessary to solve your equation and at every step, it narrows down the size since it can provide a meaningful solution(until 1e+29). This can be solved by using a fixed-step solver and setting its step size as 0.01. Then you will have reasonable spikes at the points 0 and 1 respectively. Let me know the results.
0 Commenti
Vedere anche
Categorie
Scopri di più su Additional Math and Discrete in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!