{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw2p3 - function[d1 d2 = Find the distance 1st and 2nd 3rd...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
function [d1, d2] = hw2p3() % Find the distance b/w the first to second root and third to fourth root. % 1st and 2nd root: around 3pi/2 % 3rd and 4th root: around 7pi/2 % approximate the solution to the first two roots [zp zm] = z_star(3); % perform a few steps of newton % since |z[k+1] - z[k]| = |f(z[k])| and that z >> f(z), we use 1000 % iterations at every step to reduce the search time. y = f(3,zp); while abs(y) > 1e-24 zp = zp + gap1000(3, zp); y = f(3,zp); zm = zm - gap1000(3, zm); end d1 = zp+abs(zm); % f(zp) and f(zm) are small enough such that this approximation is % already good enough [zp zm] = z_star(7); d2 = zp+abs(zm); end function y = f(n, z) trig = sin(z)^2/(1+cos(z)); y = trig - erfc(n*pi/2+z); end function dz = gap1000(n,z) % since exp(-(3*pi/2+z)^2) ~ -sqrt(pi)/2, dy is ~= -1 for all z in % interval % dy = (2*exp(-(n*pi/2+z)^2))/sqrt(pi) - cos(z); % dz = y / dy; % process 1000 iterations in a single step since dy=-1 implies that the % function is about linear around this section. y = f(n,z); dz = -1000*y; end function [zp, zm] = z_star(n) % n in either 3 or 7 here % this gives an approximate root of f(z) centered at n*pi/2 given that
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern