Cookbook: Difference between revisions

28 bytes removed ,  22 August 2012
m
→‎Parametrized Functions: no need to break lines when using the Math extension
m (→‎Parametrized Functions: no need to break lines when using the Math extension)
Line 60: Line 60:
==== Problem  ====
==== Problem  ====


One sometimes needs to define a family of functions depending on a set of parameters, e.g.,
One sometimes needs to define a family of functions depending on a set of parameters, e.g., <math>f (x, y, z; a, b, c)</math> where <math>x, y, z</math> denote a the variables on which the function operates and <math>a, b, c</math> are the parameters used to chose one specific element of the family of functions.


<math> f (x, y, z; a, b, c) </math>
For example, let's say we need to compute the time evolution of the elongation of a spring for different values of the spring constant <math>k</math>
 
where
 
<math> x, y, z </math>
denote a the variables on which the function operates and
 
<math> a, b, c </math>
 
are the parameters used to chose one specific element of the family of functions.
 
For example, let's say we need to compute the time evolution of the elongation of
a spring for different values of the spring constant  
 
<math> k </math>


==== Solution ====
==== Solution ====
 
We could solve the problem with the following code:
We could solve the problem with the following code


{{Code|Solve spring equation for different values of the spring constant|<syntaxhighlight lang="octave" style="font-size:13px">
{{Code|Solve spring equation for different values of the spring constant|<syntaxhighlight lang="octave" style="font-size:13px">
Line 102: Line 87:
==== Discussion ====
==== Discussion ====


In the above example, the function "sprime" represents a family of functions of  
In the above example, the function "sprime" represents a family of functions of the variables <math>x, t</math> parametrized by the parameter <math>k</math>.
the variables  
 
<math>x,t</math>  
 
parametrized by the parameter  
 
<math>k</math>.


The [http://www.gnu.org/software/octave/doc/interpreter/Anonymous-Functions.html#Anonymous-Functions anonympus function]
The [http://www.gnu.org/software/octave/doc/interpreter/Anonymous-Functions.html#Anonymous-Functions anonympus function]
Line 115: Line 93:
   @(x, t) sprime (x, t, k)
   @(x, t) sprime (x, t, k)
</pre>
</pre>
is a function of only  
 
<math>x,t</math>  
is a function of only <math>x, t</math> where the parameter <math>k</math> is 'frozen' to the value it has at the moment in the current scope.
where the parameter  
<math>k</math>  
is 'frozen' to the value it has at the moment in the current scope.


=== Distance between points ===
=== Distance between points ===