|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
error,defined variable seems to be undefinedHello
I use octave version 3.0.1 on Ubuntu 9.04 Linux platform and when I run the function : SolveDuffing (see files in attachment) in command prompt I receive the error : error: `t' undefined near line 3 column 8 error: evaluating argument list element number 1 error: called from `resultsplot' in file `/home/idomeneas/OctaveProjects/DuffingEquation.dir/resultsplot.m' error: called from `SolveDuffing' in file `/home/idomeneas/OctaveProjects/DuffingEquation.dir/SolveDuffing.m' The problem seems to be in calling the function in resultsplot.m file, but when I copy the commands from resultsplot.m to SolveDuffing.m and run the SolveDuffing, the plots are correct. I appreciate any help about this problem. Thank you Idomeneas [SolveDuffing.m] function SolveDuffing clear disp('Solving Duffing for different initial conditions') xo=0.;vo=0.;eps=1E-3; x0=[xo;xo+eps;xo+10.*eps]; v0=[vo;vo+eps;vo+10.*eps]; t=linspace(0.,100.,1000.); x=lsode("Duffing",[x0(1);v0(1)],t); y=lsode("Duffing",[x0(2);v0(2)],t); z=lsode("Duffing",[x0(3);v0(3)],t); resultsplot % figure(1) % plot(t,x(:,1),'b',t,x(:,2),'r') % xlabel("t") % ylabel("dx/dt") % figure(2) % plot(t,y(:,1),'b',t,y(:,2),'r') % xlabel("t") % ylabel("dx/dt") % figure(3) % plot(t,z(:,1),'b',t,z(:,2),'r') % xlabel("t") % ylabel("dx/dt") endfunction [resultsplot.m] function resultsplot figure(1) plot(t,x(:,1),'b',t,x(:,2),'r') xlabel("t") ylabel("dx/dt") figure(2) plot(t,y(:,1),'b',t,y(:,2),'r') xlabel("t") ylabel("dx/dt") figure(3) plot(t,z(:,1),'b',t,z(:,2),'r') xlabel("t") ylabel("dx/dt") endfunction [Duffing.m] %Duffing's Equation function xdot = Duffing (x,t) omega=3.5; F=0.85; xdot(1) = x(2); xdot(2) = -x(2) + 10.*x(1)-100.*x(1)*x(1)*x(1)+F*cos(omega*t); endfunction _______________________________________________ Bug-octave mailing list Bug-octave@... https://www-old.cae.wisc.edu/mailman/listinfo/bug-octave |
|
|
error,defined variable seems to be undefinedOn 29-Oct-2009, Idomeneas Pateros wrote:
| Hello | I use octave version 3.0.1 on Ubuntu 9.04 Linux platform and when I run the | function : | | SolveDuffing (see files in attachment) | | in command prompt I receive the error : | | error: `t' undefined near line 3 column 8 | error: evaluating argument list element number 1 | error: called from `resultsplot' in file | `/home/idomeneas/OctaveProjects/DuffingEquation.dir/resultsplot.m' | error: called from `SolveDuffing' in file | `/home/idomeneas/OctaveProjects/DuffingEquation.dir/SolveDuffing.m' | | The problem seems to be in calling the function in resultsplot.m file, but | when I copy the commands from resultsplot.m to SolveDuffing.m | and run the SolveDuffing, the plots are correct. | | I appreciate any help about this problem. This doesn't look like a bug in Octave. Your resultplot function doesn't have any arguments, so t (and x) will be undefined inside that function. | function resultsplot | figure(1) | plot(t,x(:,1),'b',t,x(:,2),'r') | xlabel("t") | ylabel("dx/dt") | figure(2) | plot(t,y(:,1),'b',t,y(:,2),'r') | xlabel("t") | ylabel("dx/dt") | figure(3) | plot(t,z(:,1),'b',t,z(:,2),'r') | xlabel("t") | ylabel("dx/dt") | endfunction Write this as function resultplot (x, t) and then call it with resultplot (x, t) and it should work. Unless you have a bug to report, please use the help list. jwe _______________________________________________ Bug-octave mailing list Bug-octave@... https://www-old.cae.wisc.edu/mailman/listinfo/bug-octave |
|
|
Re: error,defined variable seems to be undefinedI tried to remove the function and the endfunction commands and the program worked because the t,x,y,z variables were already defined in the SolveDuffing function.
|
| Free embeddable forum powered by Nabble | Forum Help |