Diese Präsentation wurde erfolgreich gemeldet.

# Please provide the matlab code for this question- Thank you- Consider.docx

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige  ×

1 von 2 Anzeige

# Please provide the matlab code for this question- Thank you- Consider.docx

Please provide the matlab code for this question. Thank you.
Consider the integral I =^1_1 exp(-x^2)dx Approximate the integral I with theMATLAB command quadover [-1,1] and default settings otherwise. TASK:Save the resulting approximation Iquadin the file A01.dat Approximate the integral I with the trapezoidal rule over [-1,1] (recall that the trapezoidal rule uses only the values at -1 and 1) Approximate the integral I with the composite trapezoidal rule and the interval [-1,1] into m = 20 sub-intervals of same length. TASK: Save the resulting approximation Idrapin the file A03.dat.
Solution
1)))))))))
fun1 = @(x) exp(-x.^2);
A01 = integral(fun1,-1,1);
2))))))))))))
x=-1:1;
y = exp(-x.^2);
A02 = trapz(x,y);
3)))))))))))))
function integral = cmptrap(a,b,n,f)
h = (b-a)/n;
x = [a+h:h:b-h];
integral = h/2*(2*sum(feval(f,x))+feval(f,a)+feval(f,b));
%Run with
cmptrap(-1,1,20,f)
%where â€™fâ€™ is the name of the function definition file
function y = f(x)
y = exp(-x.^2);
.

Please provide the matlab code for this question. Thank you.
Consider the integral I =^1_1 exp(-x^2)dx Approximate the integral I with theMATLAB command quadover [-1,1] and default settings otherwise. TASK:Save the resulting approximation Iquadin the file A01.dat Approximate the integral I with the trapezoidal rule over [-1,1] (recall that the trapezoidal rule uses only the values at -1 and 1) Approximate the integral I with the composite trapezoidal rule and the interval [-1,1] into m = 20 sub-intervals of same length. TASK: Save the resulting approximation Idrapin the file A03.dat.
Solution
1)))))))))
fun1 = @(x) exp(-x.^2);
A01 = integral(fun1,-1,1);
2))))))))))))
x=-1:1;
y = exp(-x.^2);
A02 = trapz(x,y);
3)))))))))))))
function integral = cmptrap(a,b,n,f)
h = (b-a)/n;
x = [a+h:h:b-h];
integral = h/2*(2*sum(feval(f,x))+feval(f,a)+feval(f,b));
%Run with
cmptrap(-1,1,20,f)
%where â€™fâ€™ is the name of the function definition file
function y = f(x)
y = exp(-x.^2);
.

Anzeige
Anzeige

### Please provide the matlab code for this question- Thank you- Consider.docx

1. 1. Please provide the matlab code for this question. Thank you. Consider the integral I =^1_1 exp(-x^2)dx Approximate the integral I with theMATLAB command quadover [-1,1] and default settings otherwise. TASK:Save the resulting approximation Iquadin the file A01.dat Approximate the integral I with the trapezoidal rule over [-1,1] (recall that the trapezoidal rule uses only the values at -1 and 1) Approximate the integral I with the composite trapezoidal rule and the interval [-1,1] into m = 20 sub-intervals of same length. TASK: Save the resulting approximation Idrapin the file A03.dat. Solution 1))))))))) fun1 = @(x) exp(-x.^2); A01 = integral(fun1,-1,1); 2)))))))))))) x=-1:1; y = exp(-x.^2); A02 = trapz(x,y); 3))))))))))))) function integral = cmptrap(a,b,n,f) h = (b-a)/n; x = [a+h:h:b-h]; integral = h/2*(2*sum(feval(f,x))+feval(f,a)+feval(f,b)); %Run with cmptrap(-1,1,20,f) %where â€™fâ€™ is the name of the function definition file function y = f(x) y = exp(-x.^2);