Numerical Analsis Notes Foes Team Plotting of = f() contour-lines with Ecel Macro isol.ls The Ecel (XP/) macro isol.ls developed b SimonLuca Santoro and kindl released in the free public domain allows to plot iso-levels or contour lines of a bi-variate eplicit function f(). The output of good and accurate qualit are not simpl static bitmap but there are true Ecel graphs that can be manipulated with the standard Ecel tools. The following picture is an eample of the macro output 8 8 6 8 Output Output 6 6 8 - - -8-6 - - 6 - - 6 8-6 8 - The version of this macro can output colored maps thanks to the Mapper macro developed b Robert de Levie for his MacroBundle collection. http://www.bowdoin.edu/~rdelevie/ecellaneous/ A detailed eplanation of this macro can be found in the book "Advanced Ecel for scientific data analsis" of the same author. Generating colored maps together with contours lines allows us to get ver interesting and beautiful graphs.
8 Output Output 6 8 8 6 6 8 - -8-6 - - 6 - - 6 8-6 8 As we can see the colors enhance the global D effect while at the same time the isolines assure the needed precision for scientific computing Other eamples are the following Output Output 6 6 8 8 6 8 6 - - - 8-6 6 8-8
.9.8.7.6.5... Output Output..5..5....6.5..7.5.8..9.5.6.7.9.8.5.5.5 The macro isol.ls outputs the graphs in separated files ls that are generall quite big ( -.5 MB). Successivel the can be re-opened an manipulated without the macro isol.ls. Note. The ip file also contains the template isol_output_t.ls. Do not write this file. It must be onl copied in the same director of the isol.ls macro The macro creates graphs in three different was: b rational function of -th degree P()/Q() b data table [i i i] b Ecel formula Algorithm The algorithm for iso-level plotting bases itself on the triangolariation of the rectangular domain D { : min ma min ma } Sntheticall the basic steps are:. Partitioning in rectangular sub-domains. Partitioning of each sub-domain in triangles. Evaluation of =f() at the vertices (P ' P ' P ') of each triangle.. Identification of the interpolation plane for the vertices of each triangle 5. Identification of the segment AB intersection of the triangle and the plane π = i ) Partitioning in rectangular sub-domains
) Partitioning of each sub-domain in triangles ) Evaluation of = f() at the vertices of each triangle: T T5 T T5. Identification of the interpolation plane for the vertices of each triangle For simplicit we refer to the triangle T Taking: = f( ) = f( ) = f( ) We define the interpolating plane p() = a+b +c The coefficients a b c are determined b the following formulas a = [( - ) + ( - ) + ( - ) ] / d b = [( - ) + ( - ) + ( - ) ] / d c = [( - ) + ( - ) + ( - ) ] / d where: d = + + - - - The more the domain is small the more the plane approimates the surface. 5) Identification of the segment AB At this step we find the segment AB intersection between the interpolation plane p() and the horiontal plane = i where i is the quote of the iso-level that we want to trace. The projection of the segment AB on the plane gives us the new segment A'B' For each side of the triangle determined b the points P ( ) P ( ) the correspondent projection point P'() is given b the formulas:
= [(a - i)( - ) + c ( - )] / m = [(a - i)( - ) + b ( - )] / m where: m = b ( - ) + c ( - ) This operation must be repeated for each side of the triangle simpl b indices permutation. Second side: -> ; -> ; -> ; -> Third side: -> ; -> ; -> ; -> At the end for each triangle we have points A' B' on the plane = belong to the projection of the segment AB. The trace A' B' image of AB on the plane approimates a little piece of the iso-level for = i. The approimation increases when the area of the sub-domains becomes small. P π: = i A B P P A' P' B' P' P' The advantage of this free-gradient method is its robustness because it can also work with irregular non differentiable surfaces. The drawback is an high computational effort (about operations for triangle) that produces a quite long elaboration time (minutes) Parametric Formulas. In order to reduce the computation time we can adopt a variant that avoids the eplicit calculus of the interpolation plane b using the parametric formulas of the triangle segments P ( ) P ( ) P ( ) The coordinates of the image points A' B' C' if eist are given b the following simpler formulas: A' = + t ( + t ( ) ) t = i B' = + t ( + t ( ) ) t = i C' = + t ( + t ( ) ) t = i We pa attention to choose onl the points where is t i
Generall this variant reduces of about / the total elaboration time- How to use the macro isol.ls First of all etract the files isol.ls and isol_output_t.ls from the pack isol.ip and put them in the same director that ou like. Now start Ecel and open the file isol.ls (it contains macros so remember to activate the macro) In the sheet input the controls are grouped in several areas Sets the output file where the plot will be created Parameters area: defines the range of and. Sets the grid of - and for the aes the number of iso-levels. Choose here the output that ou need: iso-leves coloured map or both Selects the source of the function f( ) to plot: Rational function Look-Up table Ecel function The first thing to do is the choice of the output file. Click on new button to open the dialog insert the name that ou want (eample mplot.ls) and give OK. From now on all the output will be redirect to this file until ou will change it. Now we have to choose the function source. This depends b the tpe of problem that we have. Assume for eample that we have to plot the contours of a rational function such as: ( f ) = + for < < and < < 8 and we want to plot iso-lines spaced b. from to For the beginning we chose a grid of nodes. The grid parameters influence the global accurac of the plot and of course the total elaboration time. If the plot will not look sufficientl accurate we should increase the grid. Remember onl that the time increases sharpl with the grid. (For eample if the time required for a grid is sec then the time for a 88 grid will be sec) Note. In the plotting domain the function f() must be alwas defined. If a singularit or a computation error raises the macro stops itself.
Because our function is epressed as a ratio of two polnomials we can select the rational source and input the coefficients: a = b = b 7 = Select the output iso-line Tip. Generall iso-lines are faster then colored map so at the first time is alwas convenient select the option. Successivel after the plot is adjusted we can switch to the other options: or The range and grid parameters will look like the following. Remember onl to take isol-levels in order to have a step of. because it is calculated as: Δ = ( ma min ) / ( n -) Now press Run to generate the plot 8...9.8.7.6.5.. Output Output 7.9.8.9 6.7 5.8.6.5..7.6..5.........6.8...6.8 option Iso-levels option Iso-level+mapper We can also define the function f( ) b the standard Ecel worksheet function Eample. Assume that we want to trace the Van der Waals curves using the following normalied equation ( p + / v )(v ) = 8 t where p = P/Pc v=v/vc t=t/tc are the normalie variables As known these curves are usuall plotted in the plane p-v (Clperon plane). Therefore we assume p and v obtaining t ( ) = (/ + )( ) / 8 Also In this case we could transform this epression in rational form but it is better to insert it directl as an Ecel function =(/M^+N)*(*M-)/8 in O cell
Now insert the range an grid parameters as the following. Note that we cannot set min = because the function is not defined along the aes. Now select the option iso-level + mapper and press Run. We have previous said that the plot generated are true graph that can be manipulated if we need as an other Ecel graph. For eample in the previous graph we note that the labels of the iso-levels between and.6 look quite confused because the are too close each other. It would be better eliminate them from the graph. Instead of re-creating the graph we go to the worksheet output and select the range D:P of the first row containing the values from to.6. Deleting these values we will remove the correspondent labels from the plot. It is also possible re-arrange the labels that are not well disposed b the macro It can be done simpl selecting the label and moving it with the mouse. Saving parameter setting The current formula and parameters setting can be saved b the Parameter button. Insert an identification string as we like eample van der waals and click Save. This parameter setting can be successivel recalled simpl b the Load button There are different separated lists for Rational. Look-up and Ecel function.
Data table Sometime the function is onl known b a tabulated dataset [i i i]. In that case comes useful the nd option "Look-Up". The dataset has onl this constraint: each abscissa i must have points at least. Insert the dataset [i i i] in the columns "i" "j" "k" rispectivel starting from the row Then select the option and start the macro as usual. Note that "look-up" is much slower then the other methods