I have a Problem while using global variable.

5 Ansichten (letzte 30 Tage)
Urvi
Urvi am 8 Okt. 2012
I have a system of equations as follows:
dy1/dt = f(y1,a,b,c,d,y2...) . . . . dy6/dt = f(y1,a,b,c,d,y2...)
These are my ordinary differential equations. a,b,c are changing with time and I have 12 equations for 12 such variables. All of these equations are interdependent on each other.
Now, in the beginning of my main function I have declared a,b,c as global and I have specified their initial values.
Now, I have written the equations for a,b,c.... followed by my odes, i.e. algebraic equations followed by my ordinary differential equations. I am using ode45. When I run the code, I get results but wrong because of the following reasons :
The code is not calculating new values for some global variables in each time step. The first 9 algebraic equations have the same value throughout whereas the last 3 values are changing. I cannot figure out how to pass new values for these 9 variables. As a result of this, the results for my odes are coming out be extremely absurd.
Any help/suggestion will be appreciated. Thanks.
  7 Kommentare
Urvi
Urvi am 9 Okt. 2012
I have posted it in one of the comments below. Thanks!
swaraj
swaraj am 9 Okt. 2012
if u dont mind can you pls ping to me mail.here i dont have acceses to take

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Sean de Wolski
Sean de Wolski am 8 Okt. 2012
This is a good reason to not use globals. Can you show us a snippet of your code?
Have you seen:
  21 Kommentare
Walter Roberson
Walter Roberson am 10 Okt. 2012
You initialize some of them once in your main routine when you call input_parameters() there, and then you re-initialize some of them in your other routine when you call input_parameters() again there
Urvi
Urvi am 10 Okt. 2012
Bearbeitet: Urvi am 10 Okt. 2012
But they are constants. Their value isn't changing at all. What I need to change with every time step is : global b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12; input_parameters does not contain b1 b2 b3 b4......it contains a..z(constants). I am initializing b1 b2 b3...in the present code itself.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by