You are a guest. Restricted access. Read more.
SCaVis manual

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
man:math:functions [2013/08/16 10:35]
admin [Functions with one variable]
man:math:functions [2014/12/11 23:30] (current)
admin
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"​).
Line 26: Line 27:
  
  
-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  <​javadoc sc>​jhplot.F1D</​javadoc> ​Java class (1D means one-dimensional function).
  
 <code python> <code python>
Line 32: Line 33:
 >>>​ 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 40: Line 42:
  
 To draw the function, one should specify limits during the function initialization (or later using the To draw the function, one should specify limits during the function initialization (or later using the
-methods of the Java object  ​[[/​scavis/​api/​doc.php/jhplot/​F1D|F1D]]. Then one should build a canvas and use the method "​draw"​ to plot the function.+methods of the Java object  ​<javadoc sc>​jhplot.F1D</javadoc>. Then one should build a canvas and use the method "​draw"​ to plot the function.
 In the example below, ​ we define the limits for this function (-2,5) and then we plot it:  In the example below, ​ we define the limits for this function (-2,5) and then we plot it: 
  
Line 121: 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 218: Line 206:
  
  
-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 244: Line 231:
  
 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 261: Line 248:
  
 Functions in 2 dimensions can be build by analogy ​ using the  Functions in 2 dimensions can be build by analogy ​ using the 
-Java  class [[/​scavis/​api/​doc.php/jhplot/​F3D|F3D]].+Java   <javadoc sc>​jhplot.F3D</javadoc> class.
 The example below shows how to construct and evaluate a function 3D: The example below shows how to construct and evaluate a function 3D:
  
Line 294: Line 281:
  
  
-====== ​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 314: Line 299:
  
  
- +One can also overlay several different objects. Let us show an example of how to show functions and histograms ​in 3D:
-One can also overlay several different objects. Let us show an example of how to show functions and histograms ​in3D:+
  
 {{func2D_histo.png}} {{func2D_histo.png}}
Line 341: Line 325:
 {{tag>​FND}} {{tag>​FND}}
  
-So far we have learned how to build functions in 1D (F1D class), 2D (F2D class) and 3D (F3D class). In addition to these "fixed dimension"​ classes, there is a  ​[[/​scavis/​api/​doc.php/jhplot/​F1D|FND class]] ​which can be used to build a function with arbitrary parameters and variables. To build such function is very easy and similar to the above styles, only now one should be more explicit about the names of variables. As example, below we make a function with 4 variables, called xx, yy,bb,kk:+So far we have learned how to build functions in 1D (F1D class), 2D (F2D class) and 3D (F3D class). In addition to these "fixed dimension"​ classes, there is a  
 +<javadoc sc>​jhplot.FND</javadoc> ​which can be used to build a function with arbitrary parameters and variables. To build such function is very easy and similar to the above styles, only now one should be more explicit about the names of variables. As example, below we make a function with 4 variables, called xx, yy, bb, kk:
  
 <code python> <code python>
Line 351: Line 336:
 Such functions can be evaluated at any variable values and plotted. Such functions can be evaluated at any variable values and plotted.
  
-===== Syntax overview ===== 
  
-<ifauth !@member>​ 
-<note important>​ 
-You  have a limited access to this part. 
-Unlock this text after  becoming [[/​scavis/​members/​selock| a full member]]. ​ 
-</​note>​ 
-</​ifauth>​ 
-<ifauth @member,​@admin,​@editor>​ 
- 
- 
-[[man:​math:​functions_jep|Working with FND functions]] 
- 
-</​ifauth>​ 
  
  
Line 373: Line 345:
 ===== 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 427: Line 396:
 >>>​ 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 542: Line 517:
 </​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 591: Line 530:
 [[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 612: Line 536:
 {{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>​ +
  
  
man/math/functions.txt · Last modified: 2014/12/11 23:30 by admin
CC Attribution-Share Alike 3.0 Unported
Powered by PHP Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 Valid HTML5