Matlab, how to know time step size in the plot or how can i get the ou

Click For Summary
SUMMARY

The discussion focuses on determining the time step size used in plots generated by the MATLAB ode23s solver. The user successfully implements a MATLAB script that solves a set of nonlinear differential equations and plots the results. The key insight is that the time step sizes are stored in the output vector 't' from the ode23s function, which can be accessed directly after running the solver.

PREREQUISITES
  • Understanding of MATLAB programming and syntax
  • Familiarity with the ode23s solver in MATLAB
  • Knowledge of nonlinear differential equations
  • Basic plotting techniques in MATLAB
NEXT STEPS
  • Explore MATLAB's odeset function for advanced solver options
  • Learn how to manipulate and analyze output vectors from MATLAB solvers
  • Investigate the impact of different time intervals on solution accuracy
  • Study techniques for visualizing multiple outputs in MATLAB plots
USEFUL FOR

This discussion is beneficial for MATLAB users, particularly those working with numerical solvers, engineers modeling dynamic systems, and researchers analyzing nonlinear differential equations.

wel
Gold Member
Messages
36
Reaction score
0
Since i am using MATLAB ode23s solver, it contains two MATLAB files . One contain the differential equations and another contains plotting and to run the m-files.
The code are working perfectly. Now i want to know the time step size that is using on the plot. How can i get the output of time step size. I would like to know the time step size that is using on the plot too. please help me.

=>

% 3 Nonlinear differential equations after Asymptotic expansion
% with 1-c in dc/dt differential equation

Code:
 function xpr= no(t,x)
       
      %values of parameters
        k_f= 6.7*10.^7;
        k_d= 6.03*10.^8; 
        k_n=2.92*10.^9; 
        k_p=4.94*10.^9;
        
        %Unknown parameters
        lambda_b= 0.0087;
        
        % scale parameters
        K_F= k_f * 10.^-9;
        K_D= k_d * 10.^-9; 
        K_N= k_n * 10.^-9; 
        K_P= k_p * 10.^-9;
        LAMBDA_B= lambda_b*10.^-9;
        
        %Pool Values
        P_C= 3 * 10.^(11);
        P_Q= 2.87 * 10.^(10); 
        
     % initial conditions
      c_0=x(1);
      s_0=x(2);
      q_0=x(3);
    
      %Non-linear differential equations.
      % dc_0/dtau=  c_0*(- K_F - K_D - K_N * s_0 - K_P*(1-q_0))
      % ds_0/dtau = Lambda_B * c* P_C *(1-s_0)
      % dq_0/dtau = (1-q_0)* K_P * c_0 *(P_C / P_Q)
    
    xpr= zeros(3,1);
    
    xpr(1)= c_0*(- K_F - K_D - K_N * s_0 - K_P*(1-q_0));
    xpr(2)= LAMBDA_B * c_0* P_C *(1-s_0);
    xpr(3)= (1-q_0)* K_P * c_0 *(P_C / P_Q);
    
    xpr= [xpr(1);xpr(2);xpr(3)];

% TO RUN the 3 nonlinear differential equations after asymptotic expansion.
% with 1-c in dc/dt differential equation


Code:
     format bank
      close all; 
      clear all; 
      clc; 
    
      %time interval
      ti=0; 
      tf=0.2; 
      tspan=[ti tf]; 
      
      x0=[0.25 0.02 0.98]; %initial conditions
    
      %time interval of [0 2] with initial condition vector [0.25 0.02 0.98] at time 0.
      options= odeset('RelTol',1e-4, 'AbsTol',[1e-4 1e-4 1e-4]);
      [t,x]= ode23s(@no,tspan,x0,options); 
    
      %Plotting the graphs:
      figure 
      subplot(3,1,1), plot(t,x(:,1),'r'),grid on; 
      title('3 nonlinear differential equations (with 1-c)'),ylabel('c_0'); 
    
      subplot(3,1,2), plot(t,x(:,2),'b'),grid on; 
      ylabel('s_0'); 
    
      subplot(3,1,3), plot(t,x(:,3),'g'),grid on; 
      ylabel('q_0');xlabel('Time')
 
Physics news on Phys.org
I believe your time step sizes should be stored in the 't' vector output from ode23
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
Replies
1
Views
4K
Replies
1
Views
4K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
Replies
2
Views
2K
Replies
1
Views
1K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K