How to plot the number of iterations as a function of the approximation

2 ビュー (過去 30 日間)
Lauren Stearns
Lauren Stearns 2017 年 6 月 6 日
コメント済み: Lauren Stearns 2017 年 6 月 6 日
Hello, My code provides me with an approximation of pi based on the number of iterations required to escape the Mandelbrot set. I would like to plot the number of iterations (n) as a function of the Approximation, but I can't seem to get a decent graph. I have tried just plotting n,Approximations, as well as a loglog plot (since the iterations get rather large) and I tried changing the marker size encase it was too small. I also tried to create a new loop to save the value from each iteration in a zeros matrix and plot that, but didn't really get anywhere with it. Any thoughts or ideas would be most appreciated. Here is the code:
% Fifth Version
close all;clear all; clc
%Prepared by Lauren Stearns
prompt = 'Input a small, real, positive value for epsilon. Input:';
epsilon = str2double(input(prompt,'s'));
c = 1/4 + epsilon ;
% Where epsilon is a very small, real, positive, number. such as 1e-10
z = 0;
n = 0;
while z < 2
z = z.^2 + c;
n = n+1 ;
end
Approximation = n*sqrt(epsilon);
display(Approximation)
format long
Pi = pi
Comparison = abs(((pi-Approximation)/pi))*100; %%Percent error comparison
display(Comparison)
loglog(n,Approximation,'k-', 'markersize', 12)

採用された回答

KSSV
KSSV 2017 年 6 月 6 日
I literally, have no idea on what you are doing..but this can be done to plot number of iterations and approximation. You have to rethink on what you are doing:
close all;clear all; clc
%Prepared by Lauren Stearns
prompt = 'Input a small, real, positive value for epsilon. Input:';
epsilon = str2double(input(prompt,'s'));
c = 1/4 + epsilon ;
% Where epsilon is a very small, real, positive, number. such as 1e-10
z = 0;
n = 0;
while z < 2
z = z.^2 + c;
n = n+1 ;
end
Approximation = [1:n]*sqrt(epsilon);
% display(Approximation)
format long
Comparison = abs(((pi-Approximation)/pi))*100; %%Percent error comparison
% display(Comparison)
loglog(1:n,Approximation,'k-', 'markersize', 12)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by