- #1
McLaren Rulez
- 292
- 3
Hi,
I am having a lot of trouble with Octave as I try to solve a system of ODEs. Any help is appreciated, I am a complete newbie with Octave and numerical solving.
Let's try a very simple one. Suppose I had a pair of ODEs with a and b being functions of time
[tex] \frac{da}{dt}=2ba[/tex]
[tex]\frac{db}{dt}=1[/tex]
Initial conditions are a(0)=1, b(0)=0
This is clearly the solved by [tex]a(t)=e^{t^{2}}[/tex] [tex]b(t)=t[/tex] My Octave code was this:
function xdot=f(x,t);
xdot=zeros(2,1)
xdot(1)=2*x(1)*x(2)
xdot(2)=1
endfunction
t=linspace(0,10,100);
x=lsode("f",[1;0],t)
I want to plot a(t) against t or b(t) or some combination of a and b against t. Here are my issues
1) The t=linspace() part. What numbers are appropriate? Sometimes, I got an error saying convergence failure but this combinations worked through blind luck. In general, what should I choose and why does it seem to matter? As I understand, this tells Octave to take t from 0 to 10 and have 100 intervals. I thought any numbers there would have worked?
2) This is more important. I tried plot(t,x(1)) but I got a blank plot. plot(t,x(2)) also gave me a blank plot. plot(t,x) gave me something but it's really weird. Isn't x now a column vector? I'm not sure what exactly lsode outputs here. What should be the correct command to get a(t) against t, which must of course be an exponential t squared against t graph?
There's also the fact that when I do it for my actual set of ODEs which are slightly more complicated, it inevitably hits an error or gets something 'x' undefined at a certain column and certain line. I'm quite lost :(
Thank you for you help.
I am having a lot of trouble with Octave as I try to solve a system of ODEs. Any help is appreciated, I am a complete newbie with Octave and numerical solving.
Let's try a very simple one. Suppose I had a pair of ODEs with a and b being functions of time
[tex] \frac{da}{dt}=2ba[/tex]
[tex]\frac{db}{dt}=1[/tex]
Initial conditions are a(0)=1, b(0)=0
This is clearly the solved by [tex]a(t)=e^{t^{2}}[/tex] [tex]b(t)=t[/tex] My Octave code was this:
function xdot=f(x,t);
xdot=zeros(2,1)
xdot(1)=2*x(1)*x(2)
xdot(2)=1
endfunction
t=linspace(0,10,100);
x=lsode("f",[1;0],t)
I want to plot a(t) against t or b(t) or some combination of a and b against t. Here are my issues
1) The t=linspace() part. What numbers are appropriate? Sometimes, I got an error saying convergence failure but this combinations worked through blind luck. In general, what should I choose and why does it seem to matter? As I understand, this tells Octave to take t from 0 to 10 and have 100 intervals. I thought any numbers there would have worked?
2) This is more important. I tried plot(t,x(1)) but I got a blank plot. plot(t,x(2)) also gave me a blank plot. plot(t,x) gave me something but it's really weird. Isn't x now a column vector? I'm not sure what exactly lsode outputs here. What should be the correct command to get a(t) against t, which must of course be an exponential t squared against t graph?
There's also the fact that when I do it for my actual set of ODEs which are slightly more complicated, it inevitably hits an error or gets something 'x' undefined at a certain column and certain line. I'm quite lost :(
Thank you for you help.
Last edited: