shape of a dew drop

18
C315 Numerical Analysis Project Surface Tension & The Meniscus Equation Fahd Shariff BSc Maths & Comp. Sci.

Upload: fahd-shariff

Post on 12-Nov-2014

389 views

Category:

Documents


2 download

DESCRIPTION

This paper describes finding the shape of an axi-symmetric dew drop given its volume and the contact angle with the horizontal plane it sits on.The technique uses numerical methods such as the Runge-Kutta Order 4, Secant Method and Linear Interpolation to find the shape of the meniscus. Sketches of the shape obtained are also included.

TRANSCRIPT

Page 1: Shape of a Dew Drop

C315 Numerical Analysis Project

Surface Tension &

The Meniscus Equation

Fahd Shariff BSc Maths & Comp. Sci.

Page 2: Shape of a Dew Drop

1. The Problem Surface Tension and the Meniscus Equation (Shape of a Dew Drop) The problem involves finding the shape of an axi-symmetric dew drop given its volume (V) and contact angle (θ) with the horizontal plane it sits on. This is of considerable technical interest since a container of uniform thickness made in the shape of a liquid drop resting on a non-wetting surface will be optimal in the sense of minimum material consumption for a given volume. The shape of a dew drop is given by the balance of surface tension and the internal pressure due to gravity (which must be greater than the external pressure otherwise the drop will collapse). This balance is represented by the equation

φφsin

10 r

zpds

d −+= ,

where p0 represents the pressure excess (over the external pressure) at the highest point O and φ is the angle formed by the tangent to the meridian and the horizontal axis, as shown in the Figure 2. Thus, r and z are related to φ by

,cosφ=ds

dr φsin=

ds

dz

We are also interested in finding the volume V. This is given by

φπ sin2rds

dz

dz

dV

ds

dV =×=

These equations can be integrated step-by-step away from O provided one starts with a truncated series expansion. This is necessary because…. This is given by

( )

−+=

−+=

−=

+=

20

24

0

20

22

0

220

20

112

18

3

11

161

4

1

24

11

8

11

2

1

ps

spV

ps

spz

spsr

ssp

π

φ

Given values of V and θ, our aim is to obtain p0 (correct to 4 significant figures) using numerical methods and also to find r(s), z(s). This information can then be used to obtain accurate plots of the dew drop’s cross-section.

Page 3: Shape of a Dew Drop

Figure 1. Dew Drop on Horizontal Surface

Figure 2. Cross-Section of the Dew Drop

Page 4: Shape of a Dew Drop

2. Numerical Procedure The numerical procedure is based on guessing a value for p0 and then integrating along the curve until φ = θ. The total volume is unlikely to be the required value, so we have to adjust p0, using the secant method, and repeat until it is. Secant Method: This method requires two initial guesses, x1 and x2. The Runge-Kutta method computes the volumes y1 and y2, using these two guesses for p0. The secant formula,

( ))12(

)12(223

yy

xxylumerequiredVoxx

−−−+= ,

is used to find the third guess, x3. The volume, y3, is also found. This process is repeated again, this time using x2 and x3 as initial guesses and so on, until

ε≤− lumerequiredVoy3 , for a specified tolerance ε. Then x3 is the value for p0 that

we are looking for. Runge-Kutta 4: The system of differential equations is integrated using a fourth-order Runge-Kutta integration scheme. We must provide four initial conditions (one for each element in the system) when using Runge-Kutta. Choosing Initial Conditions: At the top of the drop where r(0) = 0, the right hand

side of the equation, φφsin

10 r

zpds

d −+= , becomes indefinite. To remove this

difficulty we start integrating from the first step instead i.e. our initial conditions are:

( )

−+=

−+=

−=

+=

20

24

01

20

22

01

2201

201

112

18

3

11

161

4

1

24

11

8

11

2

1

ph

hpV

ph

hpz

hphr

hhp

π

φ

where h is the step size. Linear Interpolation: As integration proceeds, a check is made to see whether φ has attained or exceeded the value of θ. If this check returns true, integration is stopped. The volume obtained when φ = θ can then be determined accurately by linear interpolation on φ and the volume V. Two points, say (φ1,V1), (φ2,V2) are connected by a straight line. Then the volume V3 at φ3 = θ is given by,

)()(

)(13

12

1213 φφ

φφ−

−−+= VV

VV

Page 5: Shape of a Dew Drop

3. Testing Testing the Runge-Kutta Method: To check the Runge-Kutta integration scheme, we change the step size h, repeat the integration keeping p0 constant, and compare results. The following output table was produced when the RK4 method was run with decreasing step sizes. It also lists the total number of steps taken. h steps Runge-Kutta ---------------------------------------------------- 0.2 13 9.91376865384744 0.1 26 9.992762997819423 0.05 53 9.996732808349625 0.025 107 9.998730142934706 0.0125 215 9.999728935159231 0.00625 430 9.999915406553772 0.003125 861 9.999993596744698 0.0015625 1722 9.999997367331659 7.8125E-4 3444 9.999999252813307 3.90625E-4 6888 10.00000019559804 1.953125E-4 13777 10.000000393973494 The table shows that the RK4 method converges as the step size is halved. This means that it is independent of step size. We can obtain a result within our desired accuracy by choosing a suitable step size. Testing the Secant Method: The secant method is run a few times using two different initial guesses each time. The following output table lists these guesses and the values returned by the secant method (required volume = 10.0 and ε = 0.00001). Guess 1 Guess 2 Secant Result ------------------------------------------------- 1.0 2.0 0.8309485419060165 0.1 0.2 0.830948491254298 0.1 0.11 0.8309485279606491 0.2 0.3 0.8309484226270414 0.01 0.02 0.8309484916259142 Five arbitrary pairs of initial guesses were chosen and the secant method always returns nearly the same result. Moreover, accuracy can be improved by decreasing tolerance. Testing the Linear Interpolation Routine: This routine is run a few times using different points and comparing results. For example, given two points (1,1) and (3,3) we know that the y-coordinate at x=2 must be 2, because the equation of the line joining the points is given by y(x)=x. The results of running the tests are below. Point1 Point2 To Find Interpolated Result ---------------------------------------------------- (1.9,10.0) (2.1,20.0) 2.0 15.0 (2.0,4.0) (5.0,25.0) 3.0 11.0 From graphical insight we can tell that the interpolated results returned by the routine are correct.

Page 6: Shape of a Dew Drop

4. Results For final runs we need to use θ = 135o and V = 2 and 20. The program is supplied with the above values. It is also given the step size, h, which I have taken to be 0.0001. As discussed previously, the RK method is independent of step size. We must also provide two initial guesses, say 0.1 and 0.2. (All calculations are done in radians but are printed out in degrees.) The program proceeds by using the RK4 scheme followed by linear interpolation to find the volume at both guesses. The secant method then provides the next best guess based on these results. This process is repeated until the volume returned by a guess is very close to the required volume. This guess is the required value for p0. Case 1: θ = 135o , V = 2, h = 0.0001, initial guesses = 0.1 and 0.2 p0 Volume ------------------------------------------- 0.1 73.70023975122307 0.2 45.618628933895884 0.35532808718715636 27.59488119157107 0.5759039626435924 16.27314144428895 0.8539805427330928 9.60979366228202 1.1715544509280496 5.83081651117016 1.4934847834975746 3.769029945933324 1.7697036746388821 2.69955321145784 1.950380641359428 2.2059059596391113 2.025743087073881 2.034536066370253 2.040930833167272 2.002098654299844 2.0419134586792778 2.0000230243380166 2.0419243586481297 2.0000000170553993 Required p0: 2.0419243586481297 Volume: 2.0000000170553993 Error: 1.7055399315069053E-8 Hence p0 = 2.042 to 4 significant figures.

Page 7: Shape of a Dew Drop

Using RK4 to compute values for s, r, z and V using p0 = 2.042 and h=0.0001 gives: Angle s r(s) z(s) V(s) ------------------------------------------------------------------------------------------------------------------- 0.011699364842046353 2.0E-4 1.9999999861018165E-4 2.0419243565878824E-8 1.2829788991467085E-15 0.017549047372751075 3.00000000000003E-4 2.99999995309363E-4 4.594329796764919E-8 6.495080591522415E-15 0.02339873003507365 4.0E-4 3.9999998888145296E-4 8.167697402597033E-8 2.0527661737452967E-14 0.02924841287288669 5.0E-4 4.999999782840876E-4 1.2762027163632408E-7 5.011636047310367E-14 0.035098095930062835 6.0000000000001E-4 5.99999962474903E-4 1.8377319066436475E-7 1.0392128205861573E-13 0.04094777925047468 7.0000000000001E-4 6.99999940411535E-4 2.501357309459074E-7 1.9252699819191101E-13 0.04679746287799486 8.0000000000001E-4 7.999999110516194E-4 3.2670789228692285E-7 3.2844254617000853E-13 0.052647146856495984 9.0000000000002E-4 8.999998733527918E-4 4.134896744635355E-7 5.261014278978528E-13 0.05849683122985068 0.0010000000000002 9.99999826272688E-4 5.10481077222022E-7 8.018616087446539E-13 0.06434651604193156 0.0011000000000003 0.001099999768768943 6.176821002788107E-7 1.1740055162477405E-12 0.07019620133661127 0.0012000000000003 0.0011999996997991919 7.350927433204811E-7 1.6627400386639221E-12 0.07604588715776239 0.0013000000000004 0.0012999996183210695 8.627130060037632E-7 2.290196523368367E-12 0.08189557354925758 0.0014000000000004 0.0013999995232922106 1.0005428879555383E-6 3.0804307751009868E-12 0.08774526055496944 0.0015000000000005 0.0014999994136702497 1.148582388772838E-6 4.059423054060339E-12 0.09359494821877062 0.0016000000000005 0.0015999992884128205 1.3068315080229E-6 5.255078073845034E-12 0.0994446365845337 0.0017000000000006 0.001699999146477557 1.4752902452429E-6 6.69722499924266E-12 0.10529432569613137 0.0018000000000006 0.00179999898682209 1.6539585999405E-6 8.417617443866213E-12 <snip> (very long table) 134.79877483105224 1.6898999999998303 0.723980001576471 1.131762413413165 1.9981367245439727 134.8113435962033 1.6899999999998303 0.7239095318904974 1.1318333642645952 1.9982535448537808 134.8239134448785 1.6900999999998303 0.7238390466413206 1.1319042996549753 1.9983703169677112 134.83648437737628 1.6901999999998303 0.7237685458309914 1.131975219579558 1.9984870408850572 134.84905639399506 1.6902999999998303 0.7236980294615618 1.1320461240335955 1.9986037166051198 134.86162949503364 1.6903999999998303 0.7236274975350852 1.1321170130123395 1.9987203441272077 134.87420368079083 1.6904999999998302 0.723556950053616 1.1321878865110413 1.9988369234506373 134.88677895156576 1.6905999999998302 0.7234863870192102 1.1322587445249515 1.998953454574733 134.89935530765766 1.6906999999998302 0.7234158084339248 1.1323295870493204 1.999069937498826 134.911932749366 1.6907999999998302 0.7233452142998182 1.1324004140793977 1.9991863722222565 134.92451127699044 1.6908999999998302 0.7232746046189501 1.1324712256104328 1.9993027587443712 134.93709089083077 1.6909999999998302 0.7232039793933812 1.1325420216376743 1.9994190970645251 134.94967159118704 1.6910999999998302 0.7231333386251737 1.1326128021563702 1.999535387182081 134.9622533783594 1.6911999999998302 0.7230626823163909 1.1326835671617683 1.9996516290964088 134.97483625264826 1.6912999999998302 0.7229920104690976 1.132754316649116 1.9997678228068867 134.98742021435422 1.6913999999998302 0.7229213230853595 1.13282505061366 1.9998839683129004 135.00000526377798 1.6914999999998301 0.722850620167244 1.132895769050646 2.0000000656138432 Interpolating... Exact volume: 2.0000000170553993 Exact arc length: 1.691499958174186

Page 8: Shape of a Dew Drop
Page 9: Shape of a Dew Drop

Using the above data we can plot a graph, using Mathematica, of the dew drops cross-section as show below:

Figure 3. Cross-Section of Dew Drop when V=2, θ = 135o Case 2: θ = 135o , V = 20, h = 0.0001, initial guesses = 0.1 and 0.2 p0 Volume --------------------------------- 0.1 73.70023975122307 0.2 45.618628933895884 0.29122920013580006 33.2796152567376 0.3894127916027599 25.17702749674146 0.452145731721328 21.50577518106988 0.47787583582309495 20.230945564051712 0.4825370496241916 20.012128741727192 0.48279541485282507 20.000103258463916 0.48279763334135095 20.000000041754294 Required p0: 0.48279763334135095 Volume: 20.000000041754294 Error: 4.175429424435606E-8 Hence p0 = 0.4828 to 4 significant figures.

Page 10: Shape of a Dew Drop

Using RK4 to compute values for s, r, z and V using p0 = 0.4828 and h=0.0001 gives: Angle s r(s) z(s) V(s) ------------------------------------------------------------------------------------------------------------------- 0.011699364842046353 2.0E-4 1.9999999861018165E-4 2.0419243565878824E-8 1.2829788991467085E-15 0.0027662266887675344 2.0E-4 1.9999999992230215E-4 4.827976344562727E-9 3.033507004017374E-16 0.004149340059084677 3.0000000000000003E-4 2.9999999973776974E-4 1.0862946806556927E-8 1.5357129256581712E-15 0.0055324534605218694 4.0E-4 3.9999999937841716E-4 1.9311905511788216E-8 4.853611243509908E-15 0.006915566903452464 5.0E-4 4.99999998785971E-4 3.017485251870242E-8 1.1849636893094096E-14 0.008298680398249809 6.000000000000001E-4 5.999999979021579E-4 4.345178790244206E-8 2.4571407234216992E-14 0.009681793955287258 7.000000000000001E-4 6.999999966687044E-4 5.9142711754847466E-8 4.552156578661229E-14 0.011064907584938164 8.000000000000001E-4 7.99999995027337E-4 7.7247624184457E-8 7.765778227792347E-14 0.012448021297575874 9.000000000000002E-4 8.999999929197825E-4 9.776652531650722E-8 1.2439275270041023E-13 0.013831135103573746 0.0010000000000000002 9.999999902877673E-4 1.206994152929328E-7 1.8959419937637883E-13 0.015214249013305132 0.0011000000000000003 0.0010999999870730179 1.4604629427236666E-7 2.775848710323367E-13 0.016597363037143386 0.0012000000000000003 0.0011999999832172609 1.738071624301399E-7 3.93142542881871E-13 0.017980477185461866 0.0013000000000000004 0.0012999999786622225 2.039820199582818E-7 5.415000167172511E-13 0.019363591468633926 0.0014000000000000004 0.0013999999733496295 2.3657086706551985E-7 7.283451210097552E-13 0.020746705897032924 0.0015000000000000005 0.0014999999672212082 2.7157370397727975E-7 9.598207110187213E-13 0.022129820481032215 0.0016000000000000005 0.0015999999602186851 3.089905309356854E-7 1.2425246689093218E-12 0.02351293523100517 0.0017000000000000006 0.0016999999522837868 3.488213481995589E-7 1.5835099038790624E-12 <snip> 134.82932359871037 3.303500000002547 2.0344023442705823 1.7514793297925133 19.985469706580794 134.8401280387429 3.303600000002547 2.034331837857054 1.751550244146644 19.98639173152228 134.85093319033598 3.3037000000025474 2.034261318071803 1.7516211452034662 19.987313519669385 134.8617390535171 3.3038000000025476 2.0341907849164564 1.7516920329595829 19.988235070992015 134.87254562831382 3.303900000002548 2.034120238392643 1.7517629074115963 19.98915638546009 134.88335291475366 3.304000000002548 2.0340496785019924 1.7518337685561094 19.99007746304355 134.89416091286415 3.304100000002548 2.033979105246134 1.7519046163897243 19.990998303712345 134.90496962267284 3.3042000000025484 2.0339085186266996 1.7519754509090435 19.991918907436446 134.91577904420728 3.3043000000025486 2.0338379186453213 1.7520462721106693 19.99283927418584 134.92658917749495 3.304400000002549 2.033767305303632 1.752117079991204 19.993759403930532 134.93740002256345 3.304500000002549 2.0336966786032655 1.75218787454725 19.994679296640545 134.94821157944028 3.3046000000025493 2.0336260385458576 1.752258655775409 19.99559895228591 134.95902384815298 3.3047000000025495 2.0335553851330435 1.7523294236722835 19.996518370836686 134.96983682872911 3.3048000000025497 2.03348471836646 1.7524001782344756 19.997437552262944 134.9806505211962 3.30490000000255 2.0334140382477455 1.752470919458587 19.99835649653477 134.9914649255818 3.30500000000255 2.033343344778538 1.7525416473412199 19.999275203622272 135.00228004191342 3.3051000000025503 2.0332726379604775 1.752612361878976 20.000193673495566 Interpolating... Exact volume: 20.000000041754294 Exact arc length: 3.305078918010979

Page 11: Shape of a Dew Drop
Page 12: Shape of a Dew Drop

Using the above data we can plot a graph, using Mathematica, of the dew drops cross-section as show below:

Figure 4. Cross-Section of Dew Drop when V=20, θ = 135o 5. Approximation For Small V

A crude approximation to p for small V given in the problem is:

3

1

3

13

1

3

1

0 1603.3212

5

3

22

−−≈

+= VVp π

I will now test my program to verify that the value of p0 found for small V, say V=0.0001 matches that obtained from the equation above. Running with θ = 135o , V = 0.0001, h = 0.000001, initial guesses = 0.1 and 0.2 gives: p0 Volume --------------------------------------------- 0.1 73.70023975122307 0.2 45.618628933895884 0.36244982964349004 27.06034243861775 0.5993214705346611 15.49539735655687 0.9166940550908678 8.646751902192074 1.3173879266370423 4.750533974449305 1.8059308716281424 2.5899426632206244 2.391534153089956 1.4084358871701292 3.089563257657711 0.7661293058826033 3.9220485007421675 0.4173836109240588 4.91813950142554 0.22782259990811923 6.114759160737361 0.12458272377948562 7.5575977237516945 0.06823780288700135 9.302419582531668 0.037429654067252495 11.416587388533841 0.020559330609896845 13.980525075747497 0.011310815167363368 17.088465121973503 0.006236498995721983 20.84697569311532 0.0034508250638369694 25.36800426014362 0.0019210262813263291

Page 13: Shape of a Dew Drop

30.749700162446636 0.0010808458442037056 37.0324149547831 6.196319299271864E-4 44.11090741059947 3.669709011299251E-4 51.59030191226215 2.2951746385137082E-4 58.637868173090595 1.563650451117599E-4 64.06812457559852 1.1990403590183754E-4 67.03249722281222 1.0469875578799488E-4 67.94855158219154 1.0052363219093636E-4 Required p0: 67.94855158219154 Volume: 1.0052363219093636E-4 Error in volume: 5.236321909363547E-7 p0 by equation: 68.0865995090776 Difference in p0: 0.1380479268860597 Hence p0 = 67.95 correct to four significant figures. The equation gives 68.09. The difference in the two values is only 0.1380. Quite accurate! Using RK4 to compute values for s, r, z and V using p0 = 67.95 and h=0.000001 and then plotting a graph as before gives:

Figure 5. Cross-Section of Dew Drop for V=0.0001 The curve above is near circular, which is in accordance with theory.

Page 14: Shape of a Dew Drop

6. Java Source Code /** * Class: DewDrop * Description: This program uses secant, RK4 and linear interpolation to find the shape of a dew drop * @author Fahd Shariff * @version 1.4.1 * @date 3/12/02 */ public class DewDrop { //initial values set to 0.0 ; double initial_phi = 0.0 ; double initial_r = 0.0 ; double initial_z = 0.0 ; double initial_v = 0.0 ; double initial_s = 0.0 ; double theta = 0.0 ; double reqVolume = 0.0 ; double h ; //step size double p0 ; //pressure excess //Creates a new drop instance public DewDrop(double stepSize, double contactAngle, double targetVolume) { h = stepSize ; theta = Math.toRadians(contactAngle) ; //must convert to radians reqVolume = targetVolume ; } //This method sets initial conditions and is run before the RK4 method //It requires p0 and the step size public void setInitialConditions(double p0, double h) { this.p0 = p0 ; this.h = h ; double p0sq = p0*p0 ; double hsq = h*h ; initial_phi = (1/2D) * p0 * h * (1 + hsq/8) ; initial_r = h * (1 - (p0sq*hsq)/24) ; initial_z = (1/4D) * p0 * hsq *(1+(hsq/16)*(1-p0sq/3)) ; initial_v =(Math.PI/8) * p0 *hsq*hsq * (1+hsq*(1-p0sq)/12) ; initial_s = h ; } //Approximation of p0 for small V public double smallV(double v) { return Math.pow(v,-(1/3D))*3.1603 ; } //Represents the function phi public double phi(double z, double r, double phi) { return p0+z-(Math.sin(phi))/r;

Page 15: Shape of a Dew Drop

} //Represents the function r(distance from vertical axis) public double r(double phi) { return Math.cos(phi) ; } //Represents the function z (drop height) public double z(double phi) { return Math.sin(phi) ; } //Represents the function v (volume of the drop) public double v(double r, double phi) { return Math.PI*r*r*Math.sin(phi) ; } //RK4 method //returns the volume of the drop public double doRK4() { //must keep track of the prev values (for linear interpolation) double prev_phi, prev_v ; do { //the ks represent phi (angle) //the ls represent r (distance from vertical) //the ms represent z (drop height) //the ns represent v (volume) double k1 = h * phi(initial_z, initial_r, initial_phi) ; double l1 = h * r(initial_phi) ; double m1 = h * z(initial_phi) ; double n1 = h * v(initial_r, initial_phi) ; double k2 = h * phi(initial_z + m1/2, initial_r + l1/2, initial_phi + k1/2) ; double l2 = h * r(initial_phi + k1/2) ; double m2 = h * z(initial_phi + k1/2) ; double n2 = h * v(initial_r + l1/2 , initial_phi + k1/2) ; double k3 = h * phi(initial_z + m2/2, initial_r + l2/2, initial_phi + k2/2) ; double l3 = h * r(initial_phi + k2/2) ; double m3 = h * z(initial_phi + k2/2) ; double n3 = h * v(initial_r + l2/2 , initial_phi + k2/2) ; double k4 = h * phi(initial_z + m3, initial_r + l3, initial_phi + k3) ; double l4 = h * r(initial_phi + k3) ; double m4 = h * z(initial_phi + k3) ; double n4 = h * v(initial_r + l3 , initial_phi + k3) ; prev_phi = initial_phi; prev_v = initial_v ; initial_phi = initial_phi + (k1 + 2*k2 + 2*k3 + k4)/6 ; initial_r = initial_r + (l1 + 2*l2 + 2*l3 + l4)/6 ; initial_z = initial_z + (m1 + 2*m2 + 2*m3 + m4)/6 ; initial_v = initial_v + (n1 + 2*n2 + 2*n3 + n4)/6 ; initial_s = initial_s + h ;

Page 16: Shape of a Dew Drop

//print the RK4 table of results System.out.println(Math.toDegrees(initial_phi)+"\t\t"+initial_s+"\t\t"+initial_r+"\t\t"+initial_z+"\t\t"+initial_v);

}while(initial_phi < theta) ; //print out final results System.out.println(p0+"\t\t"+Math.toDegrees(initial_phi)+"\t\t"+initial_r+"\t\t"+initial_z+"\t\t"+initial_v) ; //must carry out linear interpolation now System.out.println("Interpolating...") ; //the exact volume when theta = 135 degrees: double volume = doLinearInterpolation(prev_phi,prev_v,initial_phi,initial_v,theta) ; System.out.println("Exact volume: +"+volume) ; //the exact arc length when theta=135 degrees: double arclength = doLinearInterpolation(prev_phi,initial_s-h,initial_phi,initial_s,theta) ; System.out.println("Exact arc length: "+arclength) ; return volume ; } //This method tests RK4 by using different step sizes public void testRK4() { System.out.println("h\t\tsteps\t\tRunge-Kutta") ; System.out.println("----------------------------------------------------") ; for(double i = 0.2 ; i>0.0001;i=i/2) { setInitialConditions(0.83,i) ; System.out.println(doRK4()) ; } } //This method carries out linear interpolation //Requires 2 points and the value to find public double doLinearInterpolation(double x1, double y1, double x2, double y2, double xfind) { //y-y1 = m(x-x1) double y3 = (xfind - x1)*(y2-y1)/(x2-x1)+y1 ; return y3 ; } //This method tests Linear Interpolation public void testLinearInterpolation() { System.out.println("Point1\t\tPoint2\t\tTo Find\t\tInterpolated Result") ; System.out.println("----------------------------------------------------") ; System.out.println(doLinearInterpolation(1.9,10,2.1,20,2)) ; System.out.println(doLinearInterpolation(2,4,5,25,3)) ; } //This method simply finds the volume of a drop given p0 using RK4 public double getVolume(double p) { setInitialConditions(p,h) ; return doRK4() ; }

Page 17: Shape of a Dew Drop

//This is the secant method. //Requires 2 initial guesses and desired tolerance. public void doSecant(double x1, double x2, double tolerance) { System.out.println("\np0\t\tVolume") ; System.out.println("---------------------------------") ; double y1 = getVolume(x1) ; System.out.println(x1+"\t\t"+y1) ; double y2 = getVolume(x2) ; System.out.println(x2+"\t\t"+y2) ; double x3, y3 ; do { //secant formula x3 = x2 + (reqVolume - y2)*(x2 - x1)/(y2 - y1) ; y3 = getVolume(x3) ; System.out.println(x3+"\t\t"+y3) ; //swap x1 = x2 ; x2 = x3 ; y1 = y2 ; y2 = y3 ; } while(Math.abs(y3-reqVolume) > tolerance) ; double error = Math.abs(y3-reqVolume) ; //error in volume System.out.println("\nRequired p0: "+x3+"\t\tVolume: "+y3+"\t\tError: "+error) ; } //This method tests the secant method by using different pairs of initial guesses public void testSecant() { System.out.println("Guess 1\t\tGuess 2\t\tSecant Result") ; System.out.println("------------------------------------------------------------------") ; doSecant(1.0,2.0,0.00001) ; doSecant(0.1,0.2,0.00001) ; doSecant(0.1,0.11,0.00001) ; doSecant(0.2,0.3,0.00001) ; doSecant(0.01,0.02,0.00001) ; } //The program starts execution here public static void main(String[] args) { //for v=2 and theta=135 DewDrop drop = new DewDrop(0.0001,135,2.0) ; drop.doSecant(0.1,0.2,0.000001) ; //for v=20 and theta=135 drop = new DewDrop(0.0001,135,20.0) ; drop.doSecant(0.1,0.2,0.000001) ; //for small v and theta=135

Page 18: Shape of a Dew Drop

drop = new DewDrop(0.000001,135,0.0001) ; drop.doSecant(0.1,0.2,0.000001) ; System.out.println(drop.smallV(0.0001)) ; //the actual p0 for small v } }

Fahd ShariffBSc Mathematics and Computer Science Year 3

C315 Numerical Analysis Project