Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!news2.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!newsfe25.iad.POSTED!7564ea0f!not-for-mail
From: "Nasser M. Abbasi" <nma@12000.org>
Newsgroups: comp.soft-sys.matlab
References: <hcpt4o$n8b$1@fred.mathworks.com>
Subject: Re: using global variable in equation used by ODE solver
Lines: 46
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3598
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3350
X-RFC2646: Format=Flowed; Original
X-EsetId: 321EA926BF2033396658
X-EsetScannerBuild: 5963
Message-ID: <qG2Im.43$gg6.15@newsfe25.iad>
NNTP-Posting-Host: ncdeodfefpjopplmihjclpliaacepnnh
X-Complaints-To: abuse@charter.net
X-Trace: cineoljmlfmnfokdadefjppgkgeilljambnphajdockabiooncdeodfefpjopplmmgdmmdanmgdmojgmdpnkapfhjflphnecildolkkeocphpjledgooohhgabbnmlnlomehlggnafaaoamp
NNTP-Posting-Date: Tue, 03 Nov 2009 23:04:54 UTC
Date: Tue, 3 Nov 2009 17:04:54 -0600
Xref: news.mathworks.com comp.soft-sys.matlab:582204



"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