You are a guest. Restricted access. Read more.

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

man:math:functions [2013/08/10 22:55]
admin [Information for advanced users]
man:math:functions [2014/01/21 23:02] (current)
Line 16: Line 16:
  
 ====== Functions with one variable====== ====== Functions with one variable======
-{{tag>​function F1D}}+ 
 +Functions can be defined using either strings or programically. First we will discuss how to show functions using strings and then we will show other, more flexible ​ methods.
  
 We will start this tutorial with a simple example of how to create and display a function with one and only one variable ("​x"​). We will start this tutorial with a simple example of how to create and display a function with one and only one variable ("​x"​).
 First, let us create an object representing a function: ​ First, let us create an object representing a function: ​
  
-<​jsmath>​+$
 f(x)=2*exp(-x*x/​50)+sin(pi*x)/​x f(x)=2*exp(-x*x/​50)+sin(pi*x)/​x
-</​jsmath>​+$
  
  
 Such functions are represented by the Java class [[/​scavis/​api/​doc.php/​jhplot/​F1D|F1D]] (1D means one-dimensional function). Such functions are represented by the Java class [[/​scavis/​api/​doc.php/​jhplot/​F1D|F1D]] (1D means one-dimensional function).
 +
 <code python> <code python>
 >>>​ from jhplot ​ import ​ * >>>​ from jhplot ​ import ​ *
 >>>​ f1 = F1D("​2*exp(-x*x/​50)+sin(pi*x)/​x"​) >>>​ f1 = F1D("​2*exp(-x*x/​50)+sin(pi*x)/​x"​)
 </​code>​ </​code>​
 +Here the input function is given by <​javadoc>​java.lang.String</​javadoc>​.
  
 One can evaluate this function at a certain point, say at 10,  as: One can evaluate this function at a certain point, say at 10,  as:
Line 120: Line 123:
 </​code>​ </​code>​
  
 +===== Non-parametric functions =====
  
- +The most flexible way to draw functions ​is to use codding with objects and calling third-party Java libraries directly, instead of using strings with function definitions
-===== Using Java coding ===== +This topic will be discussed in Section [[man:​math:​nonparametric | Non-parametric 
- +functions]]
-Since all classes are implemented in Java, one can use the standard Java syntax ​to draw functions+
-<code java 1 plot.java> +
-import jhplot.*; +
- +
-  class plot { +
-     ​public static void main(String[] args) { +
-     F1D f1 = new F1D("​2*exp(-x*x/​50)+sin(pi*x)/​x",​ -2.0, 5.0); +
-     HPlot c1 = new HPlot("​Canvas"​);​  +
-     ​c1.visible();​ +
-     ​c1.setAutoRange();​ +
-     ​c1.draw(f1);​ +
-    } +
-+
-</​code>​+
  
 ===== Symbolic manipulations ​ ===== ===== Symbolic manipulations ​ =====
Line 217: Line 207:
  
  
-Note that we have imported the Java class "​Color"​ from **java.awt** package. The output of this script is shown here+Note that we have imported the Java class <​javadoc>​java.awt.Color</​javadoc>​. The output of this script is shown here
  
-<hidden Click here to see the output of this script> 
 {{f1d_1.png|}} {{f1d_1.png|}}
- </​hidden>​+
  
 You can also plot objects on different pads as shown in the Section [[man:​visual:​graphics]]. You can also plot objects on different pads as shown in the Section [[man:​visual:​graphics]].
Line 243: Line 232:
  
 Functions in 2 dimensions can be build analogously using the  Functions in 2 dimensions can be build analogously using the 
-Java  class [[/​scavis/​api/​doc.php/jhplot/​F2D|F2D]].+Java  class <javadoc sc>​jhplot.F2D</javadoc>.
 The example below shows how to construct and evaluate a function 2D: The example below shows how to construct and evaluate a function 2D:
  
Line 293: Line 282:
  
  
-====== ​Displaying functions ​in 3D ======+====== ​Plotting ​in 3D ======
 {{tag>​3Dfunctions}} {{tag>​3Dfunctions}}
- 
- 
  
 F2D functions can be shown using 3D canvaces. ​ F2D functions can be shown using 3D canvaces. ​
Line 311: Line 298:
  
 {{f2d.jpg?​400|}} {{f2d.jpg?​400|}}
- 
  
  
Line 372: Line 358:
 ===== Integration ===== ===== Integration =====
  
-<ifauth !@member>​ +Numeric integration of functions is discussed in section [[man:​numeric:​integration| Integration]].  
-<note important>​ +Symbolic integrations are discussed in [[man:​symbolic:​startSymbolic calculation]] section.
-You  have a limited access to this part+
-Unlock this text after  becoming ​[[/​scavis/​members/​selocka full member]].  +
-</​note>​ +
-</​ifauth>​ +
-<ifauth @member,​@admin,​@editor>​+
  
 +Let us give a small example showing how to integrate <​m>​cos(x)^3</​m>​ using a trapezium rule. We will integrate this function between 1 and 10 using 10k iterations.
  
-Symbolic integration is currently not supported +<code python> 
- +from jhplot import F1D 
- +f1=F1D('​cos(x)^3'​) 
-</ifauth> +print f1.integral(10000,​1,​10) 
 +</code>
  
 +More examples are given in  the section [[man:​numeric:​integration| Integration]]
 ===== Differentiation ===== ===== Differentiation =====
  
Line 426: Line 409:
 >>>​ fn.simplify() >>>​ fn.simplify()
 >>>​ print '​Simplify=',​fn.toString() >>>​ print '​Simplify=',​fn.toString()
 +</​code>​
 +
 +The output is:
 +<​code>​
 Simplify= 30.0+x^4.0+x^2.0+x^4.0+y+z+h Simplify= 30.0+x^4.0+x^2.0+x^4.0+y+z+h
 </​code>​ </​code>​
 +
 </​ifauth>​ </​ifauth>​
  
 +===== Minimization ===== 
 +Please read the section [[man:​numeric:​minimization | Function minimization]]
 ======Expression Builder ====== ======Expression Builder ======
  
Line 541: Line 530:
 </​ifauth>​ </​ifauth>​
  
- 
-====== Functions using arbitrary definition ====== 
- 
-So far we have considered functions contracted using a string. One can define an arbitrary function using Jython syntax and call any Python or Java library inside such definition. We will illustrate this approach in this example: Let us consider a function which looks as: 
- 
- 
-<m 12> 
-if x>​0 ​ right y=a*x^{2}+b 
-</m> 
- 
-<m 12> 
-x=0  right  y=0  
-</m> 
- 
-<m> 
-if x< 0 right   ​y=a*x*cos(x)*b 
-</m> 
- 
-where a and b are constants. 
-To build such function using a single string is not easy, but it is possible to construct such function using the standard Jython. 
-Below we will construct such function and make a plot for a=20 and b=30: 
- 
- 
-<code python 1|t func3.py > 
-extern> func3.py 
-</​code>​ 
- 
- 
- 
-<hidden Click here to see the output of this script> 
-{{f1d_arbitrary.png|}} 
- </​hidden>​ 
- 
-In a similar way one can build any function with several variables. 
-Note that we create a class of this function "​cmt",​ where v[0] denotes variable "​x"​. For several variables, say x and y, one should use v[0] (for x) and v[1] for y. Analogously,​ one can use the same approach for x variable. 
- 
- 
-You can find more example how to create mathematical functions in 3D programmically in Section [[man:​visual:​graphics3d&#​math_objects_in_3d|3D functions]] 
  
 =======Using special functions ​ ====== =======Using special functions ​ ======
 +You can integrate special functions from third-party Java libraries
 +into your code and show them in 2D and 3D.
 <ifauth !@member>​ <ifauth !@member>​
 <note important>​ <note important>​
Line 590: Line 543:
 [[man:​math:​special_functions|Read next]] [[man:​math:​special_functions|Read next]]
 </​ifauth>​ </​ifauth>​
- 
- 
-=======Using functions from Java libraries ====== 
-<ifauth !@member>​ 
-<note important>​ 
-Unregistered users have a limited access to this section. 
-You can unlock advanced pages after  becoming [[/​scavis/​members/​selock| a full member]].  ​ 
-</​note>​ 
-</​ifauth>​ 
-<ifauth @member,​@admin,​@editor>​ 
-[[man:​math:​special_functions|Read next]] 
-</​ifauth>​ 
- 
- 
- 
  
  
Line 611: Line 549:
 {{tag>​parametric_function}} {{tag>​parametric_function}}
  
-Parametric functions can be constructed ​  +Please read the section ​[[man:​math:​parametric|Parametric ​functions]].
-using the Java class [[/​scavis/​api/​doc.php/​jhplot/​FPR|FPR]]. +
-The variables "​u"​ and "​v"​ are parametric variables used to build "​x,​y,​z"​. +
- +
-To display such functions, use the canvas [[/​scavis/​api/​doc.php/​jhplot/​HPlot3DP|HPlot3DP]]. +
- +
- +
-<code python 1|t func4.py > +
-extern> func4.py +
-</​code>​ +
- +
-The output of this script is shown here +
- +
- +
-{{paramfunc.png?​500|A parametric function}} +
- +
- +
-One can overlay several functions on top of each other and set the transparency level. In this example we show this: +
- +
-<code python 1|t func5.py > +
-extern> func5.py +
-</​code>​ +
- +
- +
-The execution of this script brings up a window with this figure: +
- +
- +
-<hidden Click here to see the output of this script>​ +
-{{sphere3d.png?​500|A parametric function from  jhplot Java package}} +
-</​hidden>​ +
  
  
Navigation

Print/export