Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

We now have all the pieces necessary to build a walk - on - spheres estimate of temperature on a square domain. Using functions from

We now have all the pieces necessary to build a walk-on-spheres estimate of temperature on a square domain. Using functions from Tasks 1,2 and 3, write a function, wos_temperature_estimate(x0, y0, length, cnr_temps, epsilon, number_walks), which returns a tuple with two items: 1) the average temperature estimate as a float, and 2) a numpy.array with the edge temperatures from each individual walk. The parameter epsilon is a float that indicates when
the distance of the walk is close enough to the edge that we can stop. The parameter number_walks is an integer indicating how many walks to take. Remember that each walk starts afresh from point x0, y0. The other parameters are as described in the earlier tasks. Refer to the algorithm descriptiont
in the figure for what to implement.
Sample
>>> x =0.6; y =0.3
>>> length =1.0; epsilon =0.01
>>> cnr_temps ={'sw':600.0,'se':700.0,'ne':1000.0,'nw':850.0}
>>> number_walks =1
>>> random.seed(1)
>>>(T_avg, Ts)= wos_temperature_estimate(x, y, length, cnr_temps, epsilon,
,-> number_walks)
>>> T_avg
635.4021168323254
>>> Ts
array([635.40211683])
>>> number_walks =100
>>> random.seed(1)
>>>(T_avg, Ts)= wos_temperature_estimate(x, y, length, cnr_temps, epsilon,
,-> number_walks)
>>> T_avg
749.4923764337983
It is possible to compute the temperature value analytically for this square domain with linearly varying boundary conditions. In this case, the value at (0.6,0.3) is the area-weighted average of the corner
temperature values, as follows:
T(0.6,0.3)= TSW\times (1.00.6)\times (1.00.3)+TSE\times 0.6\times (1.00.3)+TNE\times 0.6\times 0.3+TNW\times (1.00.6)\times 0.3
This results in T(0.6,0.3)=744 K. What do we notice from the sample usage above? The result from one walk is a terrible estimate: 635 K. This is not surprising. Remember the value gets more accurate as we take more walks. When using 100 walks, the result is 749 K, which only differs 0.6% from the analytical value of 744 K.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions