Thread Subject: using global variable in equation used by ODE solver

Subject: using global variable in equation used by ODE solver

From: Tariq

Date: 3 Nov, 2009 18:35:04

Message: 1 of 3

i have problem in my program
i created one variable 'v' in main file , the value of that variable is used in the equation in other program as global variable.

when i run main program having ode45 solver for that equation having variable 'v' it gives error
??? Error using ==> odearguments at 117
Solving EGG2 requires an initial condition vector of length 1.
can any body guide me about this.

is there is way to use value of one variable in other function (equation) which will be solved through ODE solver.
my code is

main program
--------------------
clc;
clear all;
global v;
x=[-1;1];
v= 2*x;
[x,y]= ode45(@eg,[-1 1],[0.1],v);
plot (x,y);
--------------
function dy =eg(x,y)
global v;
dy= -v*y + x;
end

Subject: using global variable in equation used by ODE solver

From: Nasser M. Abbasi

Date: 3 Nov, 2009 23:04:54

Message: 2 of 3


"Tariq " <t.umer@lancaster.ac.uk> wrote in message
news:hcpt4o$n8b$1@fred.mathworks.com...
>i have problem in my program
> i created one variable 'v' in main file , the value of that variable is
> used in the equation in other program as global variable.
>
> when i run main program having ode45 solver for that equation having
> variable 'v' it gives error
> ??? Error using ==> odearguments at 117
> Solving EGG2 requires an initial condition vector of length 1.
> can any body guide me about this.
>
> is there is way to use value of one variable in other function (equation)
> which will be solved through ODE solver.
> my code is
>
> main program
> --------------------
> clc;
> clear all;
> global v;
> x=[-1;1];
> v= 2*x;
> [x,y]= ode45(@eg,[-1 1],[0.1],v);
> plot (x,y);
> --------------
> function dy =eg(x,y)
> global v;
> dy= -v*y + x;
> end

The problem is in your eg function.
When you type "v*y", notice that v is a vector of length 2, so this causes
dy to become a vector of length 2, hence the problem.

I do not know what you are doing here. And why you are passing 'v' to ode45
since it is allready global. try v scalar, and try this

v= 99;
[x,y]= ode45(@eg,[-1 1],[0.1]);

--Nasser


Subject: using global variable in equation used by ODE solver

From: Tariq

Date: 6 Nov, 2009 14:06:03

Message: 3 of 3

hello dear,
thanks for you response , i have checked the error ,
it is ok, how i can get specific value of v from the vector having different values of v to be used in the equation in eg (eq for ode solver).

"Nasser M. Abbasi" <nma@12000.org> wrote in message <qG2Im.43$gg6.15@newsfe25.iad>...
>
> "Tariq " <t.umer@lancaster.ac.uk> wrote in message
> news:hcpt4o$n8b$1@fred.mathworks.com...
> >i have problem in my program
> > i created one variable 'v' in main file , the value of that variable is
> > used in the equation in other program as global variable.
> >
> > when i run main program having ode45 solver for that equation having
> > variable 'v' it gives error
> > ??? Error using ==> odearguments at 117
> > Solving EGG2 requires an initial condition vector of length 1.
> > can any body guide me about this.
> >
> > is there is way to use value of one variable in other function (equation)
> > which will be solved through ODE solver.
> > my code is
> >
> > main program
> > --------------------
> > clc;
> > clear all;
> > global v;
> > x=[-1;1];
> > v= 2*x;
> > [x,y]= ode45(@eg,[-1 1],[0.1],v);
> > plot (x,y);
> > --------------
> > function dy =eg(x,y)
> > global v;
> > dy= -v*y + x;
> > end
>
> The problem is in your eg function.
> When you type "v*y", notice that v is a vector of length 2, so this causes
> dy to become a vector of length 2, hence the problem.
>
> I do not know what you are doing here. And why you are passing 'v' to ode45
> since it is allready global. try v scalar, and try this
>
> v= 99;
> [x,y]= ode45(@eg,[-1 1],[0.1]);
>
> --Nasser
>
>

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
ode solver Tariq 3 Nov, 2009 13:39:02
global variable Tariq 3 Nov, 2009 13:39:02
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com