- #1
Dr.D
- 2,412
- 722
- TL;DR Summary
- A short bit of Octave code that works fine in the Command window produces errors when saved and then executed. What am I doing wrong?
I'm new to using Octave 5.1.0, and a bit confused about how to solve ODEs with Octave. Let me show you a bit of code that I grabbed off a university web site:
>> function xdot = pend(x,t) % pend.m
xdot(1) = x(2); xdot(2) = - x(1) - 0.1*x(2);
end
>> sol=lsode( "pend",[0.1, 0.2], t = linspace(0,40, 200));
>> plot( t, sol,"-@")
If I past that code into the Command window, it runs beautifully and produces the plot that would be expected.
Now, let me save that exact same bit of code as pend.m. If I go to the Command window and type "pend", I get an error message:
error: 'x' undefined near line 2 column 13
error: called from
pend at line 2 column 11
If I go to the the Editor window and load the file pend.m, when I then try to save and run it, I get the same error message as above. What am I missing here?
Help will be greatly appreciated.
PS: If it is relevant, I'm running Win10 64 bit on an HP Z210 machine.
>> function xdot = pend(x,t) % pend.m
xdot(1) = x(2); xdot(2) = - x(1) - 0.1*x(2);
end
>> sol=lsode( "pend",[0.1, 0.2], t = linspace(0,40, 200));
>> plot( t, sol,"-@")
If I past that code into the Command window, it runs beautifully and produces the plot that would be expected.
Now, let me save that exact same bit of code as pend.m. If I go to the Command window and type "pend", I get an error message:
error: 'x' undefined near line 2 column 13
error: called from
pend at line 2 column 11
If I go to the the Editor window and load the file pend.m, when I then try to save and run it, I get the same error message as above. What am I missing here?
Help will be greatly appreciated.
PS: If it is relevant, I'm running Win10 64 bit on an HP Z210 machine.