Solving Non-linear System of 3 diff eqns using ode23s in matlab

In summary, the conversation is about using ode solver in Matlab to solve three differential equations, known as the Lorenz equations. Two M-files, ode.m and lorenz.m, were created to run the solver and plot the resulting graphs. The values of the plots are not ideal and the user is seeking help in adjusting the parameters to obtain more suitable values. They also want to use function handle (@lorenz) in the lorenz.m file for better description of the problem.
  • #1
wel
Gold Member
36
0
I am trying to solve 3 differentail equations(Lorenz equations) using ode solver: ode23s in Matlab. Here are the 3 lorenz equations:

dc/dt= alpha*I*(1-c) + c*(- k_f - k_d - k_n * s - k_p*(1-q))

ds/dt = lambda_b * c* P_C *(1-s)- lambda_r *(1-q)*s

dq/dt = (1-q)* k_p * c *(P_C / P_Q)- gamma * q

I have used the ode solver and created two M-files ode.m and lorenz.m

=> Here are my two Matlab M-files. This is my 1st M-file : ode.m which i ran to plot the graph.
Code:
      format bank
      close all; 
      clear all; 
      clc; 
      
      %time interval
      ti=0; 
      tf=140; 
      tspan=[ti tf]; 
      
      x0=[0.25 0.02 0.98]; %initial vectors
      
      %time interval of [0 2] with initial condition vector [0.25 0.02 0.02] at time 0.
      options= odeset('RelTol',1e-4, 'AbsTol',[1e-4 1e-4 1e-4]);
      [t,x]= ode23s('lorenz',tspan,x0,options); 
      
      %Plotting the graphs:
      figure 
      subplot(3,1,1), plot(t,x(:,1),'r'),grid on; 
      title('Lorenz Equations'),ylabel('c'); 
      
      subplot(3,1,2), plot(t,x(:,2),'b'),grid on; 
      ylabel('s'); 
      
      subplot(3,1,3), plot(t,x(:,3),'g'),grid on; 
      ylabel('q');xlabel('t')


This is my second M-file which is lorenz.m

Code:
      % Creating the MATLAB M-file containing the Lorenz equations.
      
      function xprime= lorenz(t,x)
    
       %values of parameters
        I=1200;
        k_f= 6.7*10.^7;
        k_d= 6.03*10.^8; 
        k_n=2.92*10.^9; 
        k_p=4.94*10.^9;
        lambda_b= 0.0087;
        lambda_r =835; 
        gamma =2.74; 
        alpha =1.14437*10.^-3;
        P_C= 3 * 10.^(11);
        P_Q= 2.87 * 10.^(10);    
    
     % initial conditions
      c=x(1);
      s=x(2);
      q=x(3);
    
      %Non-linear differential equations.
      % dc/dt= alpha*I*(1-c) + c*(- k_f - k_d - k_n * s - k_p*(1-q))
      % ds/dt = lambda_b * c* P_C *(1-s)- lambda_r *(1-q)*s
      % dq/dt = (1-q)* k_p * c *(P_C / P_Q)- gamma * q
    
      xprime=[ alpha*I*(1-c) + c*(- k_f - k_d - k_n * s - k_p*(1-q)); lambda_b *(1-s)* c* P_C  - lambda_r *(1-q)*s; (1-q)*k_p * c *(P_C / P_Q)- gamma * q];

Please help me, both M-files codes are working but i want to use function handle (@lorenz) in lorenz.m file because Lorenz isn’t very descriptive of this problem. And also, when i run ode.m file , the values of plot are really small but when i run the lorenz.m file , the values of c,s,q are really big.I want to get values of s and q somewhere between 0 to 1. And value of c should be really big number something 3.5 X10^11. I don't know what is going on?
 
Physics news on Phys.org
  • #2
I'm sorry you are not generating any responses at the moment. Is there any additional information you can share with us? Any new findings?
 

Related to Solving Non-linear System of 3 diff eqns using ode23s in matlab

1. How can I solve a non-linear system of 3 differential equations using ode23s in Matlab?

To solve a non-linear system of 3 differential equations using ode23s in Matlab, you can use the following steps:

  • Define the system of equations using anonymous functions or function handles.
  • Create a vector of initial conditions for the dependent variables.
  • Set the time span for the solution.
  • Call the ode23s function with the system of equations, initial conditions, and time span as input arguments.
  • Retrieve the solution for each dependent variable using the output from ode23s.

2. What is the difference between ode23 and ode23s in Matlab?

The main difference between ode23 and ode23s in Matlab is the algorithm used for solving the system of differential equations. Ode23 uses a second and third order explicit Runge-Kutta method, while ode23s uses a second- and third-order semi-implicit Runge-Kutta method. This means that ode23s is more suitable for stiff systems of equations, while ode23 may be more efficient for non-stiff systems.

3. How do I specify the tolerances for ode23s in Matlab?

To specify the tolerances for ode23s in Matlab, you can use the 'RelTol' and 'AbsTol' options when calling the function. The 'RelTol' option sets the relative error tolerance, while the 'AbsTol' option sets the absolute error tolerance. The default values for these options are 1e-3 and 1e-6, respectively.

4. Can ode23s handle systems of more than 3 differential equations?

Yes, ode23s can handle systems of any size, including systems with more than 3 differential equations. However, the efficiency of the algorithm may decrease as the size of the system increases.

5. Are there any limitations to using ode23s in Matlab?

One limitation of ode23s in Matlab is that it cannot handle discontinuous functions or events in the system of equations. In these cases, a different solver such as ode45 may be more suitable. Additionally, ode23s may not be as efficient for non-stiff systems compared to ode23.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
907
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
950
Back
Top