This preview shows pages 1–2. Sign up to view the full content.
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) > 1e24
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);
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
This note was uploaded on 03/12/2012 for the course CS 3220 taught by Professor Marschner during the Spring '09 term at Cornell University (Engineering School).
 Spring '09
 MARSCHNER

Click to edit the document details