SlideShare a Scribd company logo
1 of 3
Download to read offline
% Runs Newton's method to find roots of f(z) . It col
function [a,n,TOL,N]=P3(a,n,TOL,N)
A=zeros(n,n,'uint8');
f = inline('z^3-1'); % Define f and f'.
fprime = inline('3*z^2');
rts=roots([1 0 0 -1])
h=2*a/n;
for j=1:n+1, % Try initial values with imaginary parts between
y = -a + (j-1)*h; % -a and a
for i=1:n+1, % and with real parts between
x = -a + (i-1)*h; % -a and a.
z = x + 1i*y;
zk = z;
kount = 0; % kount is the total number of iterations.
conv1 = 0; % conv1,2,3 count iterations when approx soln is within
conv2 = 0; % TOL of root1,2,3.
conv3 = 0;
while kount < 40 & conv1 < 5 & conv2 < 5 & conv3 < 5,
kount = kount + 1;
zk = zk - f(zk)/fprime(zk); % This is the Newton step.
if abs(zk-root1) < TOL, % Check for convergence to root1.
conv1 = conv1 + 1;
else
conv1 = 0;
end;
if abs(zk-root2) < TOL, % Check for convergence to root2.
conv2 = conv2 + 1;
else
conv2 = 0;
end;
if abs(zk-root3) < TOL, % Check for convergence to root3.
conv3 = conv3 + 1;
else
conv3 = 0;
end;
end;
if conv1 >=3, M(j,i,1) = 255; end; % Converged to root 1. Color point green.
if conv2 >=3, M(j,i,2) = 255; end; % Converged to root 2. Color point red.
if conv3 >=3, M(j,i,3) = 255; end; % Converged to root 3. Color point blue.
end;
end;
imshow(A)
Solution
% Runs Newton's method to find roots of f(z) . It col
function [a,n,TOL,N]=P3(a,n,TOL,N)
A=zeros(n,n,'uint8');
f = inline('z^3-1'); % Define f and f'.
fprime = inline('3*z^2');
rts=roots([1 0 0 -1])
h=2*a/n;
for j=1:n+1, % Try initial values with imaginary parts between
y = -a + (j-1)*h; % -a and a
for i=1:n+1, % and with real parts between
x = -a + (i-1)*h; % -a and a.
z = x + 1i*y;
zk = z;
kount = 0; % kount is the total number of iterations.
conv1 = 0; % conv1,2,3 count iterations when approx soln is within
conv2 = 0; % TOL of root1,2,3.
conv3 = 0;
while kount < 40 & conv1 < 5 & conv2 < 5 & conv3 < 5,
kount = kount + 1;
zk = zk - f(zk)/fprime(zk); % This is the Newton step.
if abs(zk-root1) < TOL, % Check for convergence to root1.
conv1 = conv1 + 1;
else
conv1 = 0;
end;
if abs(zk-root2) < TOL, % Check for convergence to root2.
conv2 = conv2 + 1;
else
conv2 = 0;
end;
if abs(zk-root3) < TOL, % Check for convergence to root3.
conv3 = conv3 + 1;
else
conv3 = 0;
end;
end;
if conv1 >=3, M(j,i,1) = 255; end; % Converged to root 1. Color point green.
if conv2 >=3, M(j,i,2) = 255; end; % Converged to root 2. Color point red.
if conv3 >=3, M(j,i,3) = 255; end; % Converged to root 3. Color point blue.
end;
end;
imshow(A)

More Related Content

More from angelfashions02

N= sp3 F = p orbital of F overlap with sp3 hybrid.pdf
                     N= sp3 F = p orbital of F overlap with sp3 hybrid.pdf                     N= sp3 F = p orbital of F overlap with sp3 hybrid.pdf
N= sp3 F = p orbital of F overlap with sp3 hybrid.pdfangelfashions02
 
I think you are missing an S species in the first.pdf
                     I think you are missing an S species in the first.pdf                     I think you are missing an S species in the first.pdf
I think you are missing an S species in the first.pdfangelfashions02
 
H2te , H2 Se, H2S , H2O .pdf
                     H2te , H2 Se, H2S , H2O                          .pdf                     H2te , H2 Se, H2S , H2O                          .pdf
H2te , H2 Se, H2S , H2O .pdfangelfashions02
 
Compound II and III only. .pdf
                     Compound II and III only.                        .pdf                     Compound II and III only.                        .pdf
Compound II and III only. .pdfangelfashions02
 
Until 2001, the 40-year-old Halamka also worked as an emergency room.pdf
Until 2001, the 40-year-old Halamka also worked as an emergency room.pdfUntil 2001, the 40-year-old Halamka also worked as an emergency room.pdf
Until 2001, the 40-year-old Halamka also worked as an emergency room.pdfangelfashions02
 
The Final Accounts of non-trading concerns consists of1. Receipts.pdf
The Final Accounts of non-trading concerns consists of1. Receipts.pdfThe Final Accounts of non-trading concerns consists of1. Receipts.pdf
The Final Accounts of non-trading concerns consists of1. Receipts.pdfangelfashions02
 
sickel cell anemia is caused by recessive allele. frequency of sicke.pdf
sickel cell anemia is caused by recessive allele. frequency of sicke.pdfsickel cell anemia is caused by recessive allele. frequency of sicke.pdf
sickel cell anemia is caused by recessive allele. frequency of sicke.pdfangelfashions02
 
I think that (e) have only non-singular generalized inversesSol.pdf
I think that (e) have only non-singular generalized inversesSol.pdfI think that (e) have only non-singular generalized inversesSol.pdf
I think that (e) have only non-singular generalized inversesSol.pdfangelfashions02
 
ConvertingSeconds.javaimport java.util.Scanner;public class Conv.pdf
ConvertingSeconds.javaimport java.util.Scanner;public class Conv.pdfConvertingSeconds.javaimport java.util.Scanner;public class Conv.pdf
ConvertingSeconds.javaimport java.util.Scanner;public class Conv.pdfangelfashions02
 
Before Attempting to measure risk aversion, following two factors sh.pdf
Before Attempting to measure risk aversion, following two factors sh.pdfBefore Attempting to measure risk aversion, following two factors sh.pdf
Before Attempting to measure risk aversion, following two factors sh.pdfangelfashions02
 
Answer The general circumstance for retaining outside experts is wh.pdf
Answer The general circumstance for retaining outside experts is wh.pdfAnswer The general circumstance for retaining outside experts is wh.pdf
Answer The general circumstance for retaining outside experts is wh.pdfangelfashions02
 
AnsConsolidated financial statements are the aggregated or combin.pdf
AnsConsolidated financial statements are the aggregated or combin.pdfAnsConsolidated financial statements are the aggregated or combin.pdf
AnsConsolidated financial statements are the aggregated or combin.pdfangelfashions02
 
Answer b)S phaseS-phase is synthetic phase where semiconservative.pdf
Answer b)S phaseS-phase is synthetic phase where semiconservative.pdfAnswer b)S phaseS-phase is synthetic phase where semiconservative.pdf
Answer b)S phaseS-phase is synthetic phase where semiconservative.pdfangelfashions02
 
a)The NLS resides somewhere between amino acids 240 and 357. b)The.pdf
a)The NLS resides somewhere between amino acids 240 and 357. b)The.pdfa)The NLS resides somewhere between amino acids 240 and 357. b)The.pdf
a)The NLS resides somewhere between amino acids 240 and 357. b)The.pdfangelfashions02
 
A database is generally used for storing related, structured data, w.pdf
A database is generally used for storing related, structured data, w.pdfA database is generally used for storing related, structured data, w.pdf
A database is generally used for storing related, structured data, w.pdfangelfashions02
 
9x^4y^10z^-2Solution9x^4y^10z^-2.pdf
9x^4y^10z^-2Solution9x^4y^10z^-2.pdf9x^4y^10z^-2Solution9x^4y^10z^-2.pdf
9x^4y^10z^-2Solution9x^4y^10z^-2.pdfangelfashions02
 

More from angelfashions02 (20)

Phenol S.pdf
                     Phenol                                      S.pdf                     Phenol                                      S.pdf
Phenol S.pdf
 
N= sp3 F = p orbital of F overlap with sp3 hybrid.pdf
                     N= sp3 F = p orbital of F overlap with sp3 hybrid.pdf                     N= sp3 F = p orbital of F overlap with sp3 hybrid.pdf
N= sp3 F = p orbital of F overlap with sp3 hybrid.pdf
 
isotopes .pdf
                     isotopes                                      .pdf                     isotopes                                      .pdf
isotopes .pdf
 
I think you are missing an S species in the first.pdf
                     I think you are missing an S species in the first.pdf                     I think you are missing an S species in the first.pdf
I think you are missing an S species in the first.pdf
 
H2te , H2 Se, H2S , H2O .pdf
                     H2te , H2 Se, H2S , H2O                          .pdf                     H2te , H2 Se, H2S , H2O                          .pdf
H2te , H2 Se, H2S , H2O .pdf
 
E=1 Solu.pdf
                     E=1                                      Solu.pdf                     E=1                                      Solu.pdf
E=1 Solu.pdf
 
Compound II and III only. .pdf
                     Compound II and III only.                        .pdf                     Compound II and III only.                        .pdf
Compound II and III only. .pdf
 
Until 2001, the 40-year-old Halamka also worked as an emergency room.pdf
Until 2001, the 40-year-old Halamka also worked as an emergency room.pdfUntil 2001, the 40-year-old Halamka also worked as an emergency room.pdf
Until 2001, the 40-year-old Halamka also worked as an emergency room.pdf
 
The Final Accounts of non-trading concerns consists of1. Receipts.pdf
The Final Accounts of non-trading concerns consists of1. Receipts.pdfThe Final Accounts of non-trading concerns consists of1. Receipts.pdf
The Final Accounts of non-trading concerns consists of1. Receipts.pdf
 
sickel cell anemia is caused by recessive allele. frequency of sicke.pdf
sickel cell anemia is caused by recessive allele. frequency of sicke.pdfsickel cell anemia is caused by recessive allele. frequency of sicke.pdf
sickel cell anemia is caused by recessive allele. frequency of sicke.pdf
 
I think that (e) have only non-singular generalized inversesSol.pdf
I think that (e) have only non-singular generalized inversesSol.pdfI think that (e) have only non-singular generalized inversesSol.pdf
I think that (e) have only non-singular generalized inversesSol.pdf
 
ConvertingSeconds.javaimport java.util.Scanner;public class Conv.pdf
ConvertingSeconds.javaimport java.util.Scanner;public class Conv.pdfConvertingSeconds.javaimport java.util.Scanner;public class Conv.pdf
ConvertingSeconds.javaimport java.util.Scanner;public class Conv.pdf
 
Before Attempting to measure risk aversion, following two factors sh.pdf
Before Attempting to measure risk aversion, following two factors sh.pdfBefore Attempting to measure risk aversion, following two factors sh.pdf
Before Attempting to measure risk aversion, following two factors sh.pdf
 
Answer The general circumstance for retaining outside experts is wh.pdf
Answer The general circumstance for retaining outside experts is wh.pdfAnswer The general circumstance for retaining outside experts is wh.pdf
Answer The general circumstance for retaining outside experts is wh.pdf
 
AnsConsolidated financial statements are the aggregated or combin.pdf
AnsConsolidated financial statements are the aggregated or combin.pdfAnsConsolidated financial statements are the aggregated or combin.pdf
AnsConsolidated financial statements are the aggregated or combin.pdf
 
Answer b)S phaseS-phase is synthetic phase where semiconservative.pdf
Answer b)S phaseS-phase is synthetic phase where semiconservative.pdfAnswer b)S phaseS-phase is synthetic phase where semiconservative.pdf
Answer b)S phaseS-phase is synthetic phase where semiconservative.pdf
 
a)The NLS resides somewhere between amino acids 240 and 357. b)The.pdf
a)The NLS resides somewhere between amino acids 240 and 357. b)The.pdfa)The NLS resides somewhere between amino acids 240 and 357. b)The.pdf
a)The NLS resides somewhere between amino acids 240 and 357. b)The.pdf
 
A database is generally used for storing related, structured data, w.pdf
A database is generally used for storing related, structured data, w.pdfA database is generally used for storing related, structured data, w.pdf
A database is generally used for storing related, structured data, w.pdf
 
9x^4y^10z^-2Solution9x^4y^10z^-2.pdf
9x^4y^10z^-2Solution9x^4y^10z^-2.pdf9x^4y^10z^-2Solution9x^4y^10z^-2.pdf
9x^4y^10z^-2Solution9x^4y^10z^-2.pdf
 
x= 38Solutionx= 38.pdf
x= 38Solutionx= 38.pdfx= 38Solutionx= 38.pdf
x= 38Solutionx= 38.pdf
 

Recently uploaded

Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
Climbers and Creepers used in landscaping
Climbers and Creepers used in landscapingClimbers and Creepers used in landscaping
Climbers and Creepers used in landscapingDr. M. Kumaresan Hort.
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital ManagementMBA Assignment Experts
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxMohamed Rizk Khodair
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 

Recently uploaded (20)

Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Climbers and Creepers used in landscaping
Climbers and Creepers used in landscapingClimbers and Creepers used in landscaping
Climbers and Creepers used in landscaping
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptx
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 

Runs Newtons method to find roots of f(z) . It col function [a.pdf

  • 1. % Runs Newton's method to find roots of f(z) . It col function [a,n,TOL,N]=P3(a,n,TOL,N) A=zeros(n,n,'uint8'); f = inline('z^3-1'); % Define f and f'. fprime = inline('3*z^2'); rts=roots([1 0 0 -1]) h=2*a/n; for j=1:n+1, % Try initial values with imaginary parts between y = -a + (j-1)*h; % -a and a for i=1:n+1, % and with real parts between x = -a + (i-1)*h; % -a and a. z = x + 1i*y; zk = z; kount = 0; % kount is the total number of iterations. conv1 = 0; % conv1,2,3 count iterations when approx soln is within conv2 = 0; % TOL of root1,2,3. conv3 = 0; while kount < 40 & conv1 < 5 & conv2 < 5 & conv3 < 5, kount = kount + 1; zk = zk - f(zk)/fprime(zk); % This is the Newton step. if abs(zk-root1) < TOL, % Check for convergence to root1. conv1 = conv1 + 1; else conv1 = 0; end; if abs(zk-root2) < TOL, % Check for convergence to root2. conv2 = conv2 + 1; else conv2 = 0; end; if abs(zk-root3) < TOL, % Check for convergence to root3. conv3 = conv3 + 1; else conv3 = 0; end;
  • 2. end; if conv1 >=3, M(j,i,1) = 255; end; % Converged to root 1. Color point green. if conv2 >=3, M(j,i,2) = 255; end; % Converged to root 2. Color point red. if conv3 >=3, M(j,i,3) = 255; end; % Converged to root 3. Color point blue. end; end; imshow(A) Solution % Runs Newton's method to find roots of f(z) . It col function [a,n,TOL,N]=P3(a,n,TOL,N) A=zeros(n,n,'uint8'); f = inline('z^3-1'); % Define f and f'. fprime = inline('3*z^2'); rts=roots([1 0 0 -1]) h=2*a/n; for j=1:n+1, % Try initial values with imaginary parts between y = -a + (j-1)*h; % -a and a for i=1:n+1, % and with real parts between x = -a + (i-1)*h; % -a and a. z = x + 1i*y; zk = z; kount = 0; % kount is the total number of iterations. conv1 = 0; % conv1,2,3 count iterations when approx soln is within conv2 = 0; % TOL of root1,2,3. conv3 = 0; while kount < 40 & conv1 < 5 & conv2 < 5 & conv3 < 5, kount = kount + 1; zk = zk - f(zk)/fprime(zk); % This is the Newton step. if abs(zk-root1) < TOL, % Check for convergence to root1. conv1 = conv1 + 1; else conv1 = 0; end; if abs(zk-root2) < TOL, % Check for convergence to root2.
  • 3. conv2 = conv2 + 1; else conv2 = 0; end; if abs(zk-root3) < TOL, % Check for convergence to root3. conv3 = conv3 + 1; else conv3 = 0; end; end; if conv1 >=3, M(j,i,1) = 255; end; % Converged to root 1. Color point green. if conv2 >=3, M(j,i,2) = 255; end; % Converged to root 2. Color point red. if conv3 >=3, M(j,i,3) = 255; end; % Converged to root 3. Color point blue. end; end; imshow(A)