Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Since I am using matlab ode23s solver, it contains two matlab files. One contains 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

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

 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); 
  tDiffs = diff(t);   % to know time step size used in the plot

  %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') 

I have got the errors: Undefined function or variable 't'.

share|improve this question
    
What do you mean by time step size? Is it the step that it is using to plot the graph? For example, t=[1 2 3];x=[1 2 3];plot(t, x); % the step is 1. Please be more specific. –  Kira Jul 15 at 16:20
    
no, this is %time interval ti=0; tf=0.2; tspan=[ti tf]; but time stepsize is different. time step size is how many step size or grid point it has in time interval of between 0 and 1. –  Manjushree Jul 16 at 1:39

1 Answer 1

up vote 1 down vote accepted

If I understand the question and the step size correctly:

The time step size can be specified in the command tspan=[ti:stepsize:tf].

So the t in [t, x] = ode23s(...) will be tspan. And if you do not specify any stepsize in your tspan then ode23s will make your t with the same size as your solution x.

Type help ode23s in MATLAB's command window and read the help provided. It can helps you.

share|improve this answer
    
matlab didn't understand this code: tspan=[ti:stepsize:tf] –  Manjushree Jul 17 at 15:22
    
What does it say? Try tspan=ti:step:tf. For example tspan=0:0.01:0.2. –  Jika Jul 17 at 15:41
    
Tried tspan=ti:step:tf, but still i got errors, saying undefined variable of t. –  Manjushree Jul 21 at 19:47
    
Where did you use t in your code ? What value of time step do you want to use ? Give an example please because I do not have errors. –  Jika Jul 21 at 20:52
    
i have used t in this code: function xpr= no(t,x) –  Manjushree Jul 24 at 20:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.