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
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.
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
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.u...@lancaster.ac.uk> wrote in message <hdc0mb$ic8$1...@fred.mathworks.com>...