matlab results different than simulink when using ode45 (and other solvers)
16 次查看(过去 30 天)
显示 更早的评论
Im doing LQT simulation on Both simulink and MATALB but I am getting different results.
I am trying to track a single state with a 4x4 state matrix A. I am using both ode45 in matlab and simulink. My state plots I am getting are similar between simulink and matlab except the state I am tracking. as you can see there is some delay in simulink i dont know where its coming from. I checked all my codes and blocks and my parameters are 100% correct and I used different solvers in simulink and results are always the same (even with discrete, different sample time, etc). Does anyone knows the reason for this disparity in my results?
Some details:
matlab: using ode45 backward in time to get my riccati equations then solving ode45 again but forward in time to get my plant.
simulink: using ode45 forward in time with initial conditions from matalb.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1305370/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1305375/image.png)
4 个评论
Raghav
2023-5-5
Hi,
There could be various reasons why you are getting different results in Simulink and MATLAB despite using the same system and parameters. Some of the reasons are:
- Solver Differences: The choice of solver in Simulink and MATLAB can affect the simulation results. The default solver used in Simulink is ode45, but in MATLAB, you are using ode45 in both backward and forward directions. Try using the same solver in both Simulink and MATLAB to see if the results match.
- Simulation Settings: In Simulink, there are several simulation settings that can affect the simulation results, such as sample time, simulation start time, stop time, and step size. Check that these settings are the same in both Simulink and MATLAB.
- Initial Conditions: Make sure that you are using the same initial conditions in both Simulink and MATLAB. If you are using different initial conditions, it could lead to different results.
- Model Parameters: Ensure that all the model parameters in both Simulink and MATLAB are identical. Any difference in the parameters can lead to different simulation results.
- Time Delay: Check for any time delay blocks in the Simulink model. A time delay can cause a difference in the results.
- Floating Point Precision: Check the floating-point precision of the Simulink model versus the MATLAB code. If there is a difference in precision, it could cause a difference in the simulation results.
- Code Implementation: Check if there is any difference in the code implementation between the Simulink and MATLAB models. Make sure that both the Simulink and MATLAB models are implementing the same equations.
By checking these possible reasons, you may be able to identify the reason for the disparity in the simulation results.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 General Applications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!