Question:
Code your own MATLAB program to find the approximate value of the
Integeral 0 to 2 ex dx with Trapezoidal rule for N = 20, i.e., t20. Also give the relative error of t20 with
Integeral 0 to 2 ex dx = e2 − 1.
(Hint: For-end loops or Elementwise operations)
To calculate the integration we shall use the trapezoidal rule given below:
%%%SCRIPT STARTS%%%
upperLimit = 2;
lowerLimit = 0;
N = 20;
h = (upperLimit - lowerLimit) / N;
y = []; % will store values of function at differnt points
for i = lowerLimit:h:upperLimit
y = [y, exp(i)];
end
%Trapezoidal rule starts
sum = y(1) + y(length(y)); %add first and last element
for i = 2:length(y)-1
sum = sum + 2*y(i); %add remaining items
multiplied by 2
end
results = sum * h / 2 %get results
actualResult = exp(2) - 1;%get actual result of the integration
absoluteError = abs(results - actualResult); %absolute error
relativeError = absoluteError/actualResult %calculate relative
error
I tried to keep the code as simple as possible. I have also commented almost every line of the code to make things easy. If incae you face trouble with the code, please feel free to comment below. I shall be glad to help you :)
Question: Code your own MATLAB program to find the approximate value of the Integeral 0 to...
Complete the following problems in Matlab environment. Copy your com mand and final answer from MATLAB command window and paste them in a word document. Submit a single word document file for the entire HW Problems: Code your own MATLAB program to find the approximate value of the integral J e dr with Trapezoidal rule for N 20, .e., 2 (formula 4.21 on Page 201 YS). Also give the relative error of t2o with de-1. (Hint: For-end loops or Elementwise...
USE MATLAB ONLY NEED MATLAB CODE MATLAB 21.4 Integrate the following function analytically and using the trapezoidal rule, with - 1,2,3, and 4: 0 (x + 2/x dx 0 Use the analytical solution to compute true percent relative crrors to evaluate the accuracy of the trapezoidal approximations. 0
Use Matlab code Consider the following function sin(x) Using the following parameters in your functions: -func: the function/equation that you are required to integrate -a, b: the integration limits n: the number of points to be used for the integration I:Integral estimate a) Write a function capable of performing numerical integration of h(x) using the composite trapezoidal rule. Use your function to integration the equation with 9 points. Write a function capable of performing numerical integration of h(x) using the...
Explain using Matlab code but also why you used the linear system please 1 Quadrature Rule A quadrature rule is a way to approximate integrals numerically i.e. using a computer). Many such quadrature rules can be derived by solving a simple linear system. Set up a linear system and then use Matlab to find the coefficients wo, W1, W2, W3, W4, W5 such that | f(x)dx = wof(0) + wif(0.2) + w2f(0.4) + w3f(0.6) +w4f(0.8) + w5f (1) for each...
please include matlab code!! [Computer Exercises 5.3.1] Find approximate values for the two integrals 1 dr 0 0 Use composite Simpson's rule with an error-Ί 10-5 [Computer Exercises 5.3.1] Find approximate values for the two integrals 1 dr 0 0 Use composite Simpson's rule with an error-Ί 10-5
MATLAB Write an m-file capable of performing numerical integration for the equation using the simpsons and trapezoidal functions: function [value, error] = simpsons(func, a, b, n, I) %retuns the value and error ret = 0; h = (b-a)/(n+1); %step size pts = a:h:b; % array of points for i=2:(n+3)/2 a = 2*i-3; b = 2*i-2; c = 2*i-1; ret = ret + (func(pts(a)) + 4*func(pts(b)) + func(pts(c))); end value = h*ret/3; error = abs(I - value)*100/I; %error between value and...
Need help with MATLAB, what code should be added to print the graph of the trapezoid rule code below? %%Matlab code for Question 5. syms X y intlx exp(x),0,2); %integration of x*exp(x) fprintf("htlntegration of x"2*exp(x) for [O 3] is %2.5f.\n,y) %Integration using Trapizoidal rule nn [100 1000]; for ii 1:2 a:0; b-3; %Integration limit ns-1:nn(i) integral Values-zeros(size(ns)); ourFunction-@(x) x.*2.*exp(x); for n-ns val(n)-trapizoidal (ourFunction,a,b,nn(i); end fprintf nlntegration of x 2*exp(x) using Trapizoidal rule for [O 3]\n') fprintf('1tTrapizoidal integration value for n-%d...
π/2 (6 3 cos x) dx 0 (a) Derive the formula for multi-segment (evenly spaced) left-hand rectangles and then use it to approximate the value of the integral with n=1; n-2; n-4 segments. Calculate the true error and relative true error for each (b) Derive the formula for multi-segment (evenly spaced) right-hand rectangles and then use it to approximate the value of the integral with n=1; n=2; n-4 segments. Calculate the true error and relative true error for each (c)...
roo _72 05 Estimate the numerical value of fºe-x dx by writing it as the sum of ſex" dx and er dx, then: (a) Use Simpson's Rule with four subintervals (i.e. n = 4) to approximate ("e-*dx. Give three decimal places. An error calculation is not required. 4 pts (b) Show that (*e-x dx < 50e-5x dx. Calculate the value of bioe-5x dx and use this to show that the value of L ex dx is negligible.5 pts so del...
Objective The usual procedure for evaluating a definite integral is to find the antiderivative of the integrand and apply the Fundamental Theorem of Calculus. However, if an antiderivative of the integrand cannot be found, then we must settle for a numerical approximation of the integral. The objective of this project is to illustrate the Trapezoidal Rule and Simpson's Rule. Description To get started, read the section 8.6 in the text. In this project we will illustrate and compare Riemann sum,...