% complex_convergence checks for the radius of convergence of a % Taylor series by plotting the modulus of the sum for a fixed value % of z (supplied by the user) as a function of the number of terms % in the sum. It is expected that z is entered as a complex % number (e.g., 0.5 + 0.2*i). % Programmer: Dick Furnstahl furnstahl.1@osu.edu % % Revision history: % 20-Apr-2005 -- original version for Physics 263 based on % test_convergence.m. % clear; % this sets variables to zero, so we start with a clean slate z = input('enter a test value of z: '); % get a value of z to try N = 500; % maximum number of terms in the series to sum % We'll create two vectors, nvec and my_sum. The i'th elements of the % vectors are referenced by nvec(i) and my_sum(i), with i starting at 1. nvec(1) = 1; % first element of the vector nvec = (1,2,3,...,N) my_sum(1) = 1 - z; % start with the sum of the z^0 and z^1 terms for n = 2:N % now add in the rest, i.e., n = 2, 3, 4, 5, ..., N nvec(n) = n; % build the nvec vector (1,2,3,4,...,N) entry by entry my_sum(n) = my_sum(n-1) + (-1)^n * (z)^n; % add the n'th term to the sum end % now make a plot of the modulus of the sum vs. the number of terms plot(nvec,abs(my_sum)); % plot(x_vector,y_vector) plots one line xlabel('n'); % add the x-axis label ylabel('sum'); % add the y-axis label