Clear Filters
Clear Filters

matlab results different than simulink when using ode45 (and other solvers)

19 views (last 30 days)
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.
  4 Comments
M.I
M.I on 26 Feb 2023
Edited: M.I on 26 Feb 2023
so upon more research I discovered that taking my values directly from matlab to simulink works better than calculating the riccati equation in simulink. It seems doing riccati equation using final values backward in time does not yield same results as using initial values to do riccati forward in time. I do not know the reason for that tho.
Raghav
Raghav on 5 May 2023
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:
  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. Time Delay: Check for any time delay blocks in the Simulink model. A time delay can cause a difference in the results.
  6. 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.
  7. 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.

Sign in to comment.

Answers (0)

Categories

Find more on General Applications in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!