

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Objective Plot erf(alphax) for 0 < x < 5 with alpha = 0.1 to 1.1 by increments of 0.2. Matlab Code 1 % Pr. 2.27, "Numerical Methods with MatLab", Gerald Recktenwald % Objective: Plot erf(alphax) % for 0 < x < 5 with alpha=0.1 to 1.1 by 0.2. % --- generate data x = linspace(0,5); alpha = 0.1 : 0.2 : 1.1; % --- plot data figure for n = 1:length(alpha) alphax = alpha(n)x; y = erf(alphax); hold on plot(x,y) end xlabel('x') ylabel('erf(alphax)') legend( num2str(alpha') ) 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 0
1 x erf(alpha*x)
Matlab Code 2 % "Numerical Methods with MatLab", Gerald Recktenwald % Problem 2. % Objective: % Plot erf(alphax) for 0 < x < 5 with alpha = 0.1 to 1.1 with increments of 0.2. % --- generate data x = linspace(0,5); alpha = 0.1 : 0.2 : 1.1; alphax = x'alpha; y = erf(alphax); % --- plot data plot(x,y) xlabel('x') ylabel('erf(alpha*x)') legend( num2str(alpha') ) 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 0
1 x erf(alpha*x)
Comments Method 1 perhaps seems more natural. Method 2 makes better use of MATLAB’s vectorized capabilities and is the more efficient, preferred way to solve this problem