Issues Replicating Simulink Model within MATLAB (2DOF)

In summary, a Simulink model is a graphical representation of a dynamic system or process created using Simulink within MATLAB. Issues may arise when replicating a Simulink model due to different versions of MATLAB and Simulink, missing toolboxes, or errors in the model configuration or code. Troubleshooting steps include checking compatibility, reviewing configuration and code, and using the MATLAB debugger. It is not possible to replicate a Simulink model within MATLAB without using Simulink, as it provides the necessary tools and integration. Best practices for replication include using consistent versions, organizing the model logically, documenting parameters, and using appropriate data types and units.
  • #1
Sirsh
267
10
Hey all,

I've been trying to debug a model I've created of a 4DOF geared system within Simulink by reproducing the results in MATLAB going from a 2DOF upwards to verify the dynamics are acting correctly.

At the moment I am purely trying to model the stiffness between two gears, my equations are simply:
Stiffness_only_eq.jpg

From my reduced Simulink model, applying an initial displacement of the pinion of 1e-3m I get this response (sorry its hard to make out):
stiffness_only_simulink_output.jpg

Obviously from the figure above, you can see the equal amplitude oscillations with opposite direction (as these gears are not on the same shaft). I zoomed into the plot and verified that the initial condition of the gear is what I set it to be.

However, I've written the following MATLAB code to try and recreate the above, but to no avail. I'm not sure where I am going wrong here..

Mainscript
Code:
clear all;
clc;
%% Defining global variables
global r_p r_g I_p I_g k_mb
% Assignment of ODE variable values:
r_p = 0.1297;   % Pinion radius (m)
r_g = 0.1297;   % Gear radius (m)
I_p = 0.0025;   % Pinion inertia (kg.m^2)
I_g = 0.0025;   % Gear inertia (kg.m^2)
k_mb = 100;
%==========================================================================
%% initial coditions for ode solver
%==========================================================================
z0 = [1e-3,0,0,0]; % Initial Conditions for ODE45.
t_span = [0 1];         % Timespan 0 - 1 second
opts = odeset('Reltol', 1e-3, 'AbsTol', 1e-3);
[t,z] = ode45(@ode2dof, t_span, z0, opts);
%==========================================================================
%% Post Processing
%==========================================================================
% Renaming the ode45 outputs for easier usage.
theta_2 = z(:,1);
theta_2d = z(:,2);
theta_3 = z(:,3);
theta_3d = z(:,4);

% Plotting
subplot(2,1,1)
plot(t,theta_2,t,theta_3), xlabel('Time (s)'), ...
    ylabel('Angular Displacement (rad)'),title('Angular Displacements'),...
    legend('theta 2','theta 3','Location', 'northwest'),grid;
subplot(2,1,2)
plot(t,theta_2d,t,theta_3d), xlabel('Time (s)'), ...
    ylabel('Angular Velocity (rad/s)'), title('Angular Velocities'),...
    legend('theta 2d', 'theta 3d','Location', 'northwest'),grid;

ODE Script
Code:
function zdot = ode2dof(t,z)
% defining global variables
global r_p r_g I_p I_g k_mb
%% S.S.E:
zdot(2) = ((k_mb*r_p)/I_p)*(z(3)*r_g-z(1)*r_p);     % theta_2dd
zdot(4) = ((k_mb*r_g)/I_g)*(z(1)*r_p-z(3)*r_g);     % theta_3dd

z(2) = zdot(1);
z(4) = zdot(3);
% Outputs
zdot = zdot';

The output plot looks like this instead:
stiffness_only_MATLAB_output.jpg

Any help would be appreciated, as I'm lost at what's going on here even though its quite a simple system.
 
Physics news on Phys.org
  • #2


Hello,

Thank you for sharing your question and code with us. After reviewing your code, I have identified a few potential issues that may be causing the discrepancy between your Simulink and MATLAB results.

1. In your ODE script, you are not initializing the remaining variables (theta_1 and theta_1d). This may be causing unexpected behavior in your simulation.

2. It appears that you are not taking into account the initial conditions of your system in your ODE script. In the ODE script, you are only using the values of theta_2 and theta_3 to calculate their derivatives, but not taking into account their initial values. This may be causing discrepancies in your results.

3. In your ODE script, you are assigning the values of z(2) and z(4) to be the derivatives of theta_2 and theta_3, respectively. However, in your main script, you are assigning the values of theta_2d and theta_3d to be the derivatives of theta_2 and theta_3. This inconsistency may be causing unexpected behavior in your results.

I would recommend reviewing your ODE script to ensure that all variables are properly initialized and that you are taking into account the initial conditions of your system. Additionally, I would suggest verifying that your main script and ODE script are consistent in the way they are handling the variables and their derivatives.

I hope this helps. Please let me know if you have any further questions or if the issue persists. Good luck with your simulation!

 

1. What is a Simulink model and how does it relate to MATLAB?

A Simulink model is a graphical representation of a dynamic system or process, created using Simulink, which is a block diagram environment within MATLAB. Simulink models can be used to simulate and analyze complex systems, such as control systems, signal processing systems, and physical systems.

2. Why might someone encounter issues when replicating a Simulink model within MATLAB?

There are several potential reasons for issues when replicating a Simulink model within MATLAB. Some common reasons include using different versions of MATLAB and Simulink, missing or incorrect toolboxes, and errors in the model configuration or code.

3. How can I troubleshoot issues with replicating a Simulink model within MATLAB?

To troubleshoot issues with replicating a Simulink model, you can start by checking for compatibility between MATLAB and Simulink versions and ensuring all required toolboxes are installed. You can also review the model configuration and code for any errors, and use the MATLAB debugger to step through the model and identify any issues.

4. Can I replicate a Simulink model within MATLAB without using Simulink?

No, a Simulink model cannot be replicated within MATLAB without using Simulink. Simulink provides the necessary tools and functionality for creating and simulating dynamic systems, and it is tightly integrated with MATLAB.

5. Are there any best practices for replicating a Simulink model within MATLAB?

Yes, there are some best practices that can help ensure successful replication of a Simulink model within MATLAB. These include using consistent versions of MATLAB and Simulink, organizing the model in a logical and modular manner, documenting the model and its parameters, and using appropriate data types and units.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
9K
  • Advanced Physics Homework Help
Replies
10
Views
6K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
6K
Back
Top