matrice problem in sim command

1 次查看(过去 30 天)
mehmed celebi
mehmed celebi 2015-5-17
Hi,
I have an extraordinary problem in simulink. I have a simulink mdl file. When I run this file from command line with sim command with a matrice name for ex: A(1,:), it gives a normal result. But when I copy the this matrice row and paste it in command line it gives another result!
(En_iyi2(5,1:5)) gives 0.45 and tracklsq3([1.5000 1.0800 0.6000 0.1200 0.5200]) gives 0.0407 , another result! Both of them is the same matrice. What is the solution. This is the tracklsq3 file:
function [yout] = tracklsq3(pid)
% Track the output of optsim to a signal of 1
% Variables a1 and a2 are shared with RUNTRACKLSQ
Kp = pid(1);
Ki = pid(2);
lambda = pid(3);
Kd = pid(4);
mu = pid(5);
simopt = simset('solver','ode23t','SrcWorkspace','Current','DstWorkspace','Current'); % Initialize sim options
[tout,xout,yout] = sim('mehmed5_48V_1kW',[0 .04],simopt);

回答(1 个)

Walter Roberson
Walter Roberson 2015-5-17
You have a difference in rounding between the actual binary numbers and what is being displayed. Try using
format long g
disp(En_iyi2(5,1:5))
and your values will probably show up differently.
In some cases, the above is not enough to find the problem. If you are on Linux or OS-X but not MS-Windows then you can use
sprintf('%.399g\n', En_iyi2(5,1:5))
to see the entire number. If you are on MS-Windows then you will need something like James Tursa's num2strexact to view all of the digits.
  1 个评论
mehmed celebi
mehmed celebi 2015-5-18
Thank you for your answer, but this is not the problem I wrote. I know the exact digit of the values. I make a matrice from real numbers. But when it was used by its name and location in the sim command, the results become different. I made something yesterday. I all copied the values of the matrice, and pasted and it works!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Model Predictive Control Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by