matrice problem in sim command

1 view (last 30 days)
mehmed celebi
mehmed celebi on 17 May 2015
Commented: mehmed celebi on 18 May 2015
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);

Answers (1)

Walter Roberson
Walter Roberson on 17 May 2015
You have a difference in rounding between the actual binary numbers and what is being displayed. Try using
format long g
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 Comment
mehmed celebi
mehmed celebi on 18 May 2015
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!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!