help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

global variables, or ...


From: gary bollenbach
Subject: global variables, or ...
Date: Mon, 17 Dec 2012 20:34:54 -0800 (PST)

Hello All,
Searching the forum archive for 'global variable' brings up 1186 posts. 
I've looked at
the last 6 yrs, in summary at least.  Script still doesn't work.  I'm sure
there is
something very elegant which would make it work.  Any advice?

thanks,
GB 

# physics problem

clear;

global a
a = input( " What is the speed of the two trains, m/s [20]: " );
global b
b = input( " How far apart are the trains when they spot each other, km [2]:
" );

# (a) calculate the deceleration
# -v^2/(2*y) = decel;
global decel
decel = (-a^2/2)*(2/(b*1000));

# (b) calculate the distance from decelerating train to impact point
function y = f(x)
   global decel
   global a
   global b
y(1) = decel/2*x(1)^2 + a*x(1) -x(2) + 0;
y(2) = 0*x(1)^2 + a*x(1) +x(2) -b*1000;
endfunction
[x, fval, info] = fsolve(@f, [0; 0])

printf( " (a) The mutual, equal deceleration, m/s^s, is [-0.2]: %.4f \n",
decel );
printf( " (b) The first x represents the time, s, to impact [58.6]. \n" );
printf( " (b) The second x represents the distance, m, from the \n" );
printf( " (b) decelerating train start point to impact point [828]. \n" );



--
View this message in context: 
http://octave.1599824.n4.nabble.com/global-variables-or-tp4648030.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]