Definition of Integral Square Error via matlab (ISE)
114 次查看(过去 30 天)
显示 更早的评论
I have to find integral square error, where error is defined below. I For the purpose of defining ISE, I have taken t= 0:0.1:100, meaning that step response is sampled every 0.1 second and its difference from the reference value of 1 is found. Is the below given definition (in matlab code) of ISE correct or do we have to multiply the ise obtained from the below code by 0.1 since the width of rectangle is 0.1 whose length is the error.
[y t]=step(clProp,0:0.1:100)
for i = 1:101
error(i) =1 - y(i);
end
error1=error*error';
ise=abs(sum(error1))
0 个评论
采纳的回答
John D'Errico
2017-8-28
Many points to make here. First, DON'T use error as a variable name. In general, it is never a good idea to use variable names that are the same as existing function names. You will one day then have a problem, and ask franticly why your code does not work.
To compute the integral, yes, you can use a sum, which would be just rectangle rule. So clearly you would have needed to multiply by the width of the rectangle. Nor was there any need to add an abs at the end there, or even to use sum! Look at what you did:
error1=error*error';
Why did you do this, and then try to sum it up? That is a dot product. It multiplies the elements of the vector, then sums them. Had you just multiplied it by deltat, that would be the desired approximation to the integral already.
Next, learn to use MATLAB, as it is designed to be used. Instead of a loop to compute the error, just use vector operations. So one line suffices instead of the loop.
err = 1-y;
deltat = 0.1;
ise = trapz(deltat,err.^2);
Even shorter, you might have done it all in one line:
ise = trapz(0.1,(1-y).^2);
4 个评论
Sambit
2022-11-24
移动:John D'Errico
2022-11-24
which function is used insted of integral squre error in simulink 2021
because it cannot run in matlab coading
John D'Errico
2022-11-24
编辑:John D'Errico
2022-11-24
Please. Do not ask questions as an answer. I've moved your question into a comment onto my answer. Anyway, your question is not even directly relevant to the one asked here by the OP, because your question is about Simulink. So really, it should be a question of its own on Answers.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!