[Top][All Lists]

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

Re: Function Returning Answer Variable

From: Przemek Klosowski
Subject: Re: Function Returning Answer Variable
Date: Mon, 26 Nov 2012 17:03:08 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121016 Thunderbird/16.0.1

On 11/26/2012 04:09 PM, Vesnog wrote:
Okay I am trying to attach it once more. I thinks now it is attached and I
have already terminated everything with a semicolon.

It's the function invocation that has to be terminated with a semicolon. More importantly, I would recommend not printing the results in the body of the function. You already return them as an array: separate calculation and printing like so:

[r, tf]=cannon_function(1,2);
printf ("[Range = %f km, Theta_final = %f degrees] \n", r, tf );

The reason why it's useful is that if you rewrite slightly, you can apply your function to vector arguments, and get multiple output values in one statement. For instance, to plot the range as a function of shot elevation you'd do

elevation = 10:5:80;
[range, tf] = vectorized_cannon_function(990,elevation);

It'll still work with print statements in the function but will look funny.

I didn't look closely at your function but it seems that you do a rough integration of the equations of motion with a fixed time step. Octave has a ton of numerical integration routines that would do a better job of that; check out the ode* functions.

reply via email to

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