Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please find the intercept of the function y = tan(x) and a circle of various rad

ID: 3700673 • Letter: P

Question

Please find the intercept of the function y = tan(x) and a circle of various radii. Only focus on the first quadrant.

Your result should return a 3x5 array (or 5x3).

For simplicity, use the function ‘fzero’ to find the intercepts.

Hints:

Write a function that takes two inputs (a radius and an approximation for fzero) and returns the intercept as an output. This will enable you to loop through different radii. radii = [1 2 4 6 8];

Divide the problem into 3 instances. For each instance, I’ve provided a different set of guesses for fzero.

approximation1 = [0.5 1 1 1 1];

%Note: 20 means no solution exists

approximation2 = [20 20 3 4 4];

approximation3 = [20 20 20 20 7];

%use this if you would like to loop through a 2D array

approximations = [0.5 1 1 1 1; 20 20 3 4 4; 20 20 20 20 7];

sol = [0 0 0 0 0; 0 0 0 0 0; 0 0 0 0 0];

%Transpose the sol array if you would like to return a 5x3 array %sol=transpose(sol);

Due to the nature of fzero (and the function tan(x)), any guess that’s too far from the intercept may diverge to infinity, returning an NaN error in MATLAB. As you can see in Figure 1, there are no solutions for the circles with radii 1,2 in the second instance of the tan(x) waveform (and only one solution for the 3rd instance). Return 0 if there is no intercept. In the provided list of guesses, I purposely set some guesses to 20 (so that they diverge). If you enter these guesses into fzero, you will get an NaN error. The best way to work around this is to use try and catch statements. Try and catch statements are notoriously used in coding as a way of exception handling. In this assignment, your exceptions will be the data points where no intercept exists.

Explanation / Answer

if true % code end compt=0; T_edge=[0.1 0.2]; threshold=15; [FileName,PathName] = uigetfile('*.*','Select the image file'); nomfich=[PathName,FileName]; % Read the sample image in imo=imread(nomfich); imo = imresize(imo, [300 300]); SI=size(imo); im=rgb2gray(imo);%figure(11); imshow(im); h=figure(1); imshow(imo);set(h,'name',nomfich); edgeim = edge(im,'canny', T_edge, 1); figure, imshow(edgeim); [edgelist, labelededgeim] = edgelink(edgeim, 10); h = waitbar(0,'Please wait...Analysis can be time consuming for High Resolution image'); Nmax=max(max(labelededgeim)); SC=zeros(1000,2,100); for uu=1:Nmax waitbar(uu/Nmax,h) [r,c] = find(labelededgeim==uu); rc = [r c]; [sx sy]=size(rc); [imx,imy]=size(labelededgeim); n1=zeros(imx,imy); for i=1:sx x1=rc(i,1); y1=rc(i,2); n1(x1,y1)=255; end % Storing the extracted image in an array Cn1=ait_imneg(n1); [y,x]=find(Cn1==0); cerne=[y,x]; delta_sq = diff(cerne).^2; perimeter = sum(sqrt(sum(delta_sq,2))); P(uu)=perimeter/length(cerne); if P(uu) > threshold Pu(uu)=uu; compt=compt+1; disp('THE AGE OF THE WOOD IS '); disp(compt); SC(1:length(cerne),:,compt)=cerne; disp('good'); %perimeter/length(cerne) metric_string = [sprintf('R %d ', compt)];%,sprintf(' '), sprintf('P %d', P(uu))]; figure(1);hold on;plot(x,y,'g.');hold on; text(mean(x)-5,min(y)+5,metric_string,'Color','y',... 'FontSize',11,'FontWeight','bold'); else disp('NOT A RING'); end end disp(sprintf('age of the wood is %d',compt)); close(h);