Prev: ode45
Next: conditional sum
From: Tariq on 9 Nov 2009 14:12 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
From: Torsten Hennig on 9 Nov 2009 16:30 > 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.
From: Tariq on 10 Nov 2009 10:26 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
From: Thomas V on 18 Nov 2009 09:05 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(a)lancaster.ac.uk> wrote in message <hdc0mb$ic8$1(a)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
|
Pages: 1 Prev: ode45 Next: conditional sum |