MATLAB - please help!! ---------------------------------- Given the function f(x
ID: 3109331 • Letter: M
Question
MATLAB - please help!!
----------------------------------
Given the function f(x) = 2/Squareroot pi =e^x^2, write a MATLAB function to do the following: Calculate the integral integral^x=1 _x=0 f middot dx using the trapezoidal rule, with intervals of h = Delta x = 0.001. *This integral, integral^a _0 2/Squareroot pi e^-x^2 is known as the error function, erf(a). It is a common integral in statistics. For example, if a large data set has a normal distribution with a standard deviation sigma, then erf(r/sigma Squareroot 2) is the probability of a random data point falling within plusminus r of the mean value. So, the probability of a random number falling within one standard deviation of the mean would be erf (sigma/sigma Squareroot 2) = erf (1/Squareroot 2) = 0.683, or 68.3%.Explanation / Answer
Matlab Code:
%Trapezoidal_rule
a=0;
b=1;
h=0.001;
n=(b-a)/h;
i=1;
sum=0;
for x=0:0.001:1
f(i)=2/(sqrt(pi))*exp(-x^2);
i=i+1;
end
for i=2:1:(n)
sum=sum+f(i);
end
Integration=h/2*(f(1)+2*sum+f(n+1))
Output is 0.8427.
The above is the matlab code, direct .m file is impossible to upload at chegg
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.