how to avoid rounding off error in simulink calculations?

8 ビュー (過去 30 日間)
roro6992
roro6992 2014 年 6 月 22 日
コメント済み: roro6992 2014 年 6 月 23 日
Hi, I have a simulink model including a level 2 S function block. The code in the s function ia a numerical scheme that solves a PDE . When this code is run as a script alone the results are exactly accurate..but when the model is simulated they results differ from the accurate ones. I have checked and compared the results thoroughly and I guess in the very first step there is a rounding off error which is causing the results to differ. With each iteration the error is getting summed up. Is there any way to avoid this error?? Please help. I am using all variables in double data type. Please answer. Thanks.
  2 件のコメント
dpb
dpb 2014 年 6 月 22 日
Insufficient data...
What is the input that varies for starters and how much is it off the expected value?
roro6992
roro6992 2014 年 6 月 23 日
the input comes from a from a 'from workspace' block and its giving proper value. but the error is in the first step the output value should come 46.7889e5. but it comes 46.7890e5. And this error in the initial o/p reflects in the next iterations (as next step o/p depends on previous state o/p)and the error is quite big after a large no. of steps. How to circumvent this problem??

サインインしてコメントする。

採用された回答

Kaustubha Govind
Kaustubha Govind 2014 年 6 月 23 日
The difference between 46.7889e5 and 46.7890e5 is 10, which is too large to be a rounding error. Most likely, what is happening is that the From Workspace block is interpolating your data because the time-steps corresponding to your data points don't match with the simulation solver time-steps exactly. You may want to either adjust the time values in your workspace data, or uncheck the "Interpolate Data" option on the From Workspace block dialog.
  2 件のコメント
roro6992
roro6992 2014 年 6 月 23 日
As i have a very input few data points i need to interpolate them to get the corresponding input values in the intermediate time steps.The From workspace block is doing tht work. As it is a discrete state model the solver sample time is set to the sample time of the From Workspace block too. The sample time is set to 15 secs. The same code when run just as a script gives accurate values. But the o/p differs when i am simulating the model. Why this is happening. Its so confusing!! Please help. Thnks a lot!
roro6992
roro6992 2014 年 6 月 23 日
Its done. There was an error in the code. Thanks anyway :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGeneral Applications についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by