help-octave
[Top][All Lists]
Advanced

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

RE: global variables, or ...


From: Richardson, Anthony
Subject: RE: global variables, or ...
Date: Tue, 18 Dec 2012 13:54:24 +0000

> From: address@hidden [mailto:help-octave-> address@hidden On Behalf Of gary 
> bollenbach
> 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" );

Ignore my previous post.  You had the function definition in your post.  It was 
line wrapped by by email reader.

Anyway,  your script seems to run fine for me.  Are the values you get 
incorrect?

Tony Richardson


reply via email to

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