Solve 3 Coupled ODEs with NDSolve - Error Fix & Alternatives

  • Thread starter Thread starter bayan
  • Start date Start date
  • Tags Tags
    Coupled Ode
Click For Summary

Discussion Overview

The discussion revolves around solving a set of three coupled first-order ordinary differential equations (ODEs) using the NDSolve function, focusing on error handling and alternative methods for numerical solutions. The scope includes technical explanations and potential software alternatives for solving ODEs.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant shares their NDSolve code for solving three coupled ODEs and reports an error related to division by zero, specifically "Infinite expression 1/0.^2 encountered."
  • Another participant does not identify any issues with the original code and provides an alternative approach using different variable definitions and a small epsilon to avoid division by zero.
  • A participant inquires whether NDSolve worked for the second contributor and asks if the code is intended for Mathematica.
  • One participant expresses uncertainty about the software, initially thinking NDSolve is part of MATLAB, and mentions using a chemical flowsheeting program as an alternative solver without encountering the same issue.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the original code's validity, as one participant encounters an error while another does not. Multiple approaches and software options are discussed without resolution on the best method.

Contextual Notes

There is a lack of clarity regarding the definitions and behavior of the variables involved, particularly at the initial condition where t approaches zero. The discussion also highlights potential software differences that may affect the implementation of the ODEs.

Who May Find This Useful

Individuals interested in numerical methods for solving ordinary differential equations, particularly those using NDSolve in Mathematica or similar software, may find this discussion relevant.

bayan
Messages
202
Reaction score
0
Hi, I need to solve 3 coupled first order ODE's using NDSolve (numerical solution).

This is the code I have used ;

NDSolve[{u'[t] == ((1 - (u[t]/t^2))/(-3 - (u[t]/t^2) - (v[t]/t^2))),
v'[t] == (((u[t]/t^2) - (v[t]/t^2))/(-3 - (u[t]/t^2) - (v[t]/t^2))),
w'[t] == (v[t])/(-3 t^2 - (u[t]) - (v[t])),
u[0] == 0., v[0] == 0., w[0] == 0.}, {u, v, w}, {t, 0.1, 1}]

where u,v and w are functions of t and at t=0, u=v=w=0. However I am getting the following error "Infinite expression 1/0.^2 encountered", but I can't see where the division by zero occurs. Originally t was from 0 to 1, but I tried making it from 0.1 to 1 to ensure no division by zero's were taking place.

Any ideas on how to fix the code? or an alternative way of solving these ode?

Regards
 
Physics news on Phys.org
I don't see anything wrong, sorry. Even tried to solve:
Code:
u as realvariable (initial, 0)  ;
v as realvariable (initial, 0)  ;
w as realvariable (initial, 0)  ;

eps as realparameter (1e-5)  ;
t as realvariable (eps)  ;

t = time + eps  ;
 
$u = ((1 - (u/t^2))/(-3 - (u/t^2) - (v/t^2)))  ;
$v = (((u/t^2) - (v/t^2))/(-3 - (u/t^2) - (v/t^2)))  ;
$w = (v)/(-3*t^2 - (u) - (v))  ;
(the $ stands for a time derivative in this simulator)
and that worked:
uvw.jpg
 
thanks for your reply.

Did NDSolve with the options given work for you? or do you recommend the use of another software to solve those odes?

btw is that code for mathematica?

Regards
 
I don't know where NDSolve lives ? Ah, I googlesee: in MatLab. Don't have that at my disposition.

I abused a chemical flowsheeting program as equation solver, just to see if I would get the same problem as you. Apparently not.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 41 ·
2
Replies
41
Views
10K
  • · Replies 3 ·
Replies
3
Views
8K