For this problem you will write a function that calculates


For this problem you will write a function that calculates avalue between zero and one for each element in a 512x512 matrix(yes thats 512x512). The call to the function will bebeetle(xmin,ymin,xmax,ymax). The element A(1,1)will use values xmin, ymin for calculations and the elementA(512,512) will use xmax, ymax for calculations. Intermediateelements will use evenly spaced values for x and y between xmin,ymin and xmax, ymax.

At each element location in the matrix you are to do thefollowing:

a. set an iteration counter, and twovariables r and s to zero.

b. Repeat the following whiler*r+s*s<=and number of iterations is less than 255

      i. Replace s withr*r-s*s+xi where xi is the value of x assoxciated witht the currentelement.

     ii. replace s with2*r*s+yi where yi is the value of y associated witht the currentelement. Note that the r used here must be the past value of rbefore it was changed in the previous step.

      iii. Increase the countervariable by 1.

c. Once you have exited the loop you willhave recorded the number of iterations required to haver^2+s^2>4 in the iteration counter. This will be a numberbetween 0 and 255. The number to be stored in the element A(i,j)will be 1-counter_valuee/255 so that the stored value is between 0and 1.

d. repeat the abouve for all elements in aremembering that each element will have a different x, ypair.   

To test your function call it with the following argumentsbeetle(-1.5,-1.0,0.5,1.0). You want to save the result but notprint it. To see if you have done a good job run the followingMATLAB commands on the saved matrix:

>>imagesec(A); colormap(gray); %assumes matrix stored inA

You should see an interesting figure window appear on thescreen and the name of the function may make more sense.

Note: I found that a good way to get the correct x and yvalues is to create an x vector of length 512 with values form xminto xmax using linespace. A y vector can be created in the samemanner.

Request for Solution File

Ask an Expert for Answer!!
Civil Engineering: For this problem you will write a function that calculates
Reference No:- TGS0797925

Expected delivery within 24 Hours