I have a Problem while using global variable.

1 次查看(过去 30 天)
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 个评论
Urvi
Urvi 2012-10-9
I have posted it in one of the comments below. Thanks!
swaraj
swaraj 2012-10-9
if u dont mind can you pls ping to me mail.here i dont have acceses to take

请先登录,再进行评论。

回答(1 个)

Sean de Wolski
Sean de Wolski 2012-10-8
This is a good reason to not use globals. Can you show us a snippet of your code?
Have you seen:
  21 个评论
Walter Roberson
Walter Roberson 2012-10-10
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 2012-10-10
编辑:Urvi 2012-10-10
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Translated by