Thread Subject: how to using multiple values of vector for ODE solver equation

Subject: how to using multiple values of vector for ODE solver equation

From: Tariq

Date: 9 Nov, 2009 19:12:04

Message: 1 of 4

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
??? Subscript indices must either be real positive integers or logicals.

can any body guide me about this.

how to get the value of variable v in fuction equation which will be used by 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]);
plot (x,y);
--------------
function dy =eg(x,y)
global v;
z=v(i);
dy= -z*y + x;
end

Subject: how to using multiple values of vector for ODE solver equation

From: Torsten Hennig

Date: 10 Nov, 2009 07:30:11

Message: 2 of 4

> 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
> ??? Subscript indices must either be real positive
> integers or logicals.
>
> can any body guide me about this.
>
> how to get the value of variable v in fuction
> equation which will be used by 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]);

x must be a scalar (it's the independent variable)

> plot (x,y);
> --------------
> function dy =eg(x,y)
> global v;
> z=v(i);

i is undefined.

> dy= -z*y + x;
> end

Best wishes
Torsten.

Subject: how to using multiple values of vector for ODE solver equation

From: Tariq

Date: 10 Nov, 2009 15:26:03

Message: 3 of 4

hello dear Torsten .
i have initialized' i' in my main function and use it in other function for getting value of v(i) and 'i' and increased the 'i' after every iteration of ode solver .
my objective is to get the corresponding value of 'v' from the vector 'v' for every value of 'x' .
when i run this program it gives this error.
??? Error using ==> odearguments at 117
Solving EGG1A requires an initial condition vector of length 1.

my program is as under.
 main program
 --------------------
 clc;
clear all;
global v i;
i=i+1;
x=[-1;1];
v= 2*x;
[x,y]= ode45(@egg1a,[-1 1],[0.1]);
 plot (x,y);
--------------
function dy =egg1a(x,y)
global v i ;
z=v(i);
dy= -z*y + x;
 end
_________________________
some time i also get this error
??? Subscript indices must either be real positive
integers or logical.
 
 can you guide me about this.
regards

Subject: how to using multiple values of vector for ODE solver equation

From: Thomas V

Date: 18 Nov, 2009 14:05:23

Message: 4 of 4

Hi,

I try your programm and didn't get your error message. Obsviously i change the value for i to 1 or 2 in order to get a value. The initialization of i was missing.

I have change your programm as following, but it could certainly be done more efficient.

 clc;
clear all;
global v i;
i=0;
x=[-1,1];
X=[];
Y=[];
v= 2*x;
while i<2
i=i+1;
[tempx,tempy]= ode45(@egg1a,[-1 1],[0.1]);
X=[X tempx];
Y=[Y tempy];
end
subplot(1,2,1)
 plot (X(:,1),Y(:,1));
subplot(1,2,2)
plot (X(:,2),Y(:,2));

function dy =egg1a(x,y)

global v i ;
z=v(i);
dy= -z*y + x;

I am using on hold version of Matlab so you could have to do some adjustment.

Cheers,

Thomas

"Tariq " <t.umer@lancaster.ac.uk> wrote in message <hdc0mb$ic8$1@fred.mathworks.com>...
> hello dear Torsten .
> i have initialized' i' in my main function and use it in other function for getting value of v(i) and 'i' and increased the 'i' after every iteration of ode solver .
> my objective is to get the corresponding value of 'v' from the vector 'v' for every value of 'x' .
> when i run this program it gives this error.
> ??? Error using ==> odearguments at 117
> Solving EGG1A requires an initial condition vector of length 1.
>
> my program is as under.
> main program
> --------------------
> clc;
> clear all;
> global v i;
> i=i+1;
> x=[-1;1];
> v= 2*x;
> [x,y]= ode45(@egg1a,[-1 1],[0.1]);
> plot (x,y);
> --------------
> function dy =egg1a(x,y)
> global v i ;
> z=v(i);
> dy= -z*y + x;
> end
> _________________________
> some time i also get this error
> ??? Subscript indices must either be real positive
> integers or logical.
>
> can you guide me about this.
> regards

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
using ode solve... Tariq 9 Nov, 2009 14:14:10
rssFeed for this Thread

Contact us at files@mathworks.com