How to plot a single variable function defined by a integral (for example, Gaussian error fucntion, erf(x)) more efficiently?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dear all,
I want to know how to plot a single variable function defined by a integral more efficiently?
For example, Gaussian error fucntion,
.
![Gaussian error function](https://www.mathworks.com/matlabcentral/answers/uploaded_files/611640/image.png)
I know that erf(x) is a build-in function of MATLAB. But I want to know the general way to do this. Currently I am using a for-loop to achieve it. Here is my MATLAB code. Thank you.
clearvars; close all; clc;
f = @(t) (2.0/sqrt(pi))*exp(-t.^2);
x = linspace(-3,3,61);
fval = zeros(1,numel(x));
for i=1:numel(x)
fval(i) = integral(f,0,x(i),'RelTol',1e-15);
end
hf = figure; plot(x,fval,x,erf(x));
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Function Creation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!