How to find maximum value of function and return x in simulink
Show older comments
I have a problem with finding maximum value of function which I got on output.My function is very similar to simple sinus and I need to find maximum value of it and for this value return x as a new output. I can only use simulink for this problem, without matlab function or S-function.
Anyone can help?
2 Comments
Azzi Abdelmalek
on 15 Jan 2013
Can you explain if you want the maximum value at the end or during simulation?
Blazej
on 15 Jan 2013
Answers (2)
Azzi Abdelmalek
on 15 Jan 2013
Edited: Azzi Abdelmalek
on 15 Jan 2013
0 votes
You can calculate (using unit delay or memory and sum block) out(n)-out(n-1), when it becomes negative, it's your first maximum
Azzi Abdelmalek
on 15 Jan 2013
Edited: Azzi Abdelmalek
on 16 Jan 2013
You can use Matlab function block with the code:
function y = fcn(u)
%#codegen
persistent k up test
if isempty(k)
k=0
up=0;
test=0;
end
e=u-up
if or(e<0,test==1)
y=k
test=1;
else
k=k+1
y=0
up=u
end
Categories
Find more on Simulink Real-Time in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!