Info

This question is closed. Reopen it to edit or answer.

Hi, i have to implement an algorithm in simulink. The algorithm computes some unknown parameters through a iterative approach.

3 views (last 30 days)
I have written the .m file for this algorithm and wish to use this file as a matlab function block in the simulink model.
Here is a look at the code,
function y = fcn1® %#codegen coder.extrinsic('format') a = 0.03; b = 629000; c = 0.00;
R1 = R.'; format long n = [a b c]; n1 = n.'; m = [0.2 10 0.1]; m1 = m.'; i = 1; square = zeros(100000,1); min = 10000000000000000000000; N = zeros(3,1);
while gt(n1(2,1),590000) && lt(n1(2,1),650000) && gt(m1(2,1),0.000001)
A = zeros(10000,3); % defining matrix A
A(:,1) = myfunction1(n1(2,1),n1(3,1));
A(:,2) = myfunction2(n1(1,1),n1(2,1),n1(3,1));
A(:,3) = myfunction3(n1(1,1),n1(2,1),n1(3,1));
B = A.';
Y = myfunction4(n1(1,1),n1(2,1),n1(3,1));
s = R1 - Y;
ssquare = 0;
for p = 1:10000
ssquare = ssquare + s(p,1)*s(p,1);
end
square(i,1) = ssquare ;
i = i+1;
if(square(i-1,1)< min)
min = square(i-1,1);
N = n1;
end
k = B * A;
P = B * s;
m1 = k\P;
n1 = n1 + m1;
% iterating the value of n1
end
y = N(2,1); end
Actually, this is a very simplified version of the code. It has to be modified further and it will use several while loops further and compare the results of each while loop and come up with the least value out of them. This is very similar to global optimization algorithm using 'Multstart'.
So, 2 questions. 1. Can this algorithm be implemented directly on simulink without using matlab script? or this is the right approach?
2. The input to this function R should be a 1*10000 matrix or array as u call it. I have this input in a mat file right now which is a 2 10000 matrix basically. I connected my function block from this file and displayed the output in a display sink. Now, logically the model should execute the function block with this input and give me one output value. But i wonder, the display block output keeps changing dynamically during the run time of the simulation. I am confused what this run time is doing exactly? Is my function block even receiving a complete 1 10000 matrix values which is the 2nd row of mat file at the start of simulation? i want to see it working as it works as matlab code. Give the input file as input to function and receive an output value after execution.
Please suggest something. Thank you!

Answers (0)

This question is closed.

Community Treasure Hunt

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

Start Hunting!