8. Write a MATLAB function that will take as inputs a set of data (x,y) and output the best estimate of the integral using a Romberg Array. The function should perform two trapezoidal integrations using the full interval and half the interval, and then combine these integrations in a Romberg Array. Your function should also output the relative error of the integral. Please note that the data entered may not be evenly spaced and your function should make sure that at least 3 data points were entered and that the x- and yvectors containing the data are the same length. Hint: Use interpolation to obtain the required points for the trapezoidal integrations function [integral, err] = Romberg(x,y)
Code:
%Define a function romberg()
function r = romberg(f,a,b,n)
%Compute width
h = (b - a) ./ (2.^(0:n-1));
%Define r
r(1,1) = (b - a) * (f(a) + f(b)) / 2;
%Loop until length
for j = 2:n
%Declare variables
subtotal = 0;
%Loop until length
for i = 1:2^(j-2)
%Compute total
subtotal = subtotal + f(a + (2 * i - 1) * h(j));
%End
end
%Compute value
r(j,1) = r(j-1,1) / 2 + h(j) * subtotal;
%Loop until length
for k = 2:j
%Compute r
r(j,k) = (4^(k-1) * r(j,k-1) - r(j-1,k-1)) / (4^(k-1) - 1);
%End
end
%End
end;
8. Write a MATLAB function that will take as inputs a set of data (x,y) and...
(Matlab) Suppose we have a function “hw5f.m” that takes as input x and outputs the value for a function f(x). Write a Matlab program that inputs: • interval [a, b]; • m, the number of data points with evenly spaced nodes from x1 = a to xm = b, and values from f(x); • location z satisfying x2 < z < xm−1, where h = (b − a)/(m − 1); and outputs the value of the interpolaton polynomial using only...
IN MATLAB Write a MATLAB function that can be used by a user to perform polynomial interpolation using Lagrange Interpolation Method on a set of data. You should name your function as YourInitials_Lagrange_interpolation. 1. FUNCTION INPUT: . The input data pairs x and f(x) should be expressed as vectors and are used to construct the interpolation polynomials The interpolating data points/value The order of interpolating polynomials to be used. For this project you code should handle first order, second order...
1. (25 pts) Given the following start for a Matlab function: function [answer] = NewtonForm(m,x,y,z) that inputs • number of data points m; • vectors x and y, both with m components, holding x- and y-coordinates, respectively, of data points; • location z; and uses divided difference tables and Newton form to output the value of the Lagrange polynomial, interpolating the data points, at z. 1. (25 pts) Given the following start for a Matlab function: function [answer] NewtonForm(m.x.yz) that...
1. (25 pts) Write a Matlab function with the header function [value- polynomialpiece(m,x.y,k,z) that inputs number of data points m; vectors a and y, both with m components, holding r- and y-coordinates, respec- tively, of data points, and where the components of r are evenly spaced and in increasing order (rk/2,z,n+1-k/2) an even number k and a location distinct from the 0, > z . nodes; and outputs, using Lagrange form, the value at z of the deg S k-1...
Questions a) Write a (Matlab) function, which accepts the following inputs: -the finite set of Fourier series coefficients a-N, a-N+1,.. , a-1, ao, a1, aN-1, aN the fundamental period T of the signal to be reconstructed a vector t representing the times for which the signal will be constructed - and produces as output xv(t) (i.e., the output of the (Matlab) function should be a vector x of length equal to the length of t containing the values of xN...
Write a Matlab function called sine_Taylor that inputs a positive integer n, a number x, and outputs the nth Taylor polynomial of the sine function. Compute the absolute and error for n = 1: 10 at x = 1, obtained by comparing the output of your function to that of Matlab's built in sine function. Type on the Matlab console format long, then compute the previous error. Repeat the operation by typing format short. Comment on the result (quantify the...
Matlab please Using the X and Y values below, write a MATLAB function SECOND_DERIV in MATLAB. The output of the function should be the approximate value for the second derivative of the data at x, the input variable of the function Use the forward difference method and interpolate to get your final answer. X=[1,1.2,1.44,1.73,2.07,2.49,2.99,3.58,4.3,5.16,6. 19,7.43,8.92, 10.7,12.84,15.41,18.49]; Y=[18.89,19.25,19.83,20.71,21.96,23.6,25.56,27.52,28.67,27.2,19.38,-2.05,-50.9,-152.82,-354.73,-741.48,-1465.11];
1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector containing the values of the integral (A) for n= 1,2,3,..., n. The function must use the relation (B) and the value of y(1). Your function must preallocate the array that it returns. Use for loop when writing your code. b) Write MATLAB script that uses your function to calculate the values of the integral (A) using the recurrence relation (B), y(n) for n=1,2,... 19...
Using the X and Y values below, write a MATLAB function SECOND_DERIV in MATLAB. The output of the function should be the approximate value for the second derivative of the data at x, the input variable of the function. Use the forward difference method and interpolate to get your final answer. X=[1,1.2,1.44,1.73,2.07,2.49,2.99,3.58,4.3,5.16,6.19,7.43,8.92,10.7,12.84,15.41,18.49]; Y=[18.89,19.25,19.83,20.71,21.96,23.6,25.56,27.52,28.67,27.2,19.38,-2.05,-50.9,-152.82,-354.73,-741.48,-1465.11];
Create a MATLAB function to perform Lagrange Interpolation. Your function will be used as illustrated below: >> ya = Lagrange(x, y, a) where "x" is a vector of ? independent data values, "y" is a vector of ? dependent function values corresponding to "x", "a" is an arbitrary value of "x" for which you want to know the Westimate of "y", and "ya" is the estimate of the function at x=a. Print an error message and exit the function if...