Question

In: Computer Science

Use MATLAB to write a function subroutine horner_yourlastname(a, x0, d) that uses Horner’s algorithm to evaluate...

Use MATLAB to write a function subroutine horner_yourlastname(a, x0, d) that uses Horner’s algorithm to evaluate a polynomial at a given point x0.

This code should have three inputs in the order specified above:

a: a vector of coefficients of the polynomial of interest. The first element of the vector should be the leading coefficient, and the last element should be the trailing coefficient. i. e. The polynomial p(x) = anx n + an−1x n−1 . . . a1x + a0 should have associated vector a = [an, an−1, . . . , a1, a0].

x0: the point at which the polynomial is to be evaluated.

d ∈ {0, 1}: a toggle that allows the function to be evaluated at the point if d = 0 or its derivative to be evaluated at the point if d = 1.

Solutions

Expert Solution

Hey,

Note: Brother function file are not meant to be run directly they are either run through the command window or some script and should be saved with the same name mentioned below. In case of any queries brother just comment in box I would be very happy to assist all your queries.  


=====================================

Save file as horner_yourlastname.m

=====================================

function y=horner_yourlastname(a, x0, d)
y=0;
if(d==0)
for i=1:length(a)
y=y*x0+a(i);
end
else
n=length(a)-1;
vec=n:-1:1;
a(length(a))=[];
v=a.*vec;
for i=1:length(v)
y=y*x0+v(i);
end
end
end

=====================================

Executable command to test

====================================

horner_yourlastname([5:-1:1],1.3,1)

Kindly revert for any queries

Thanks.


Related Solutions

In MATLAB write a function secant.m to apply the secant method. function [x,i] = secant(f, x0,...
In MATLAB write a function secant.m to apply the secant method. function [x,i] = secant(f, x0, x1, tol, maxiters) [x,i] = secant(f, x0, x1, tol, maxiters) performs the secant method with f(x), starting at x_0 = x0 and x_1 = x1, and continuing until either |x_i+1 - x_i| <= tol, or maxiters iterations have been taken. The number of iterations, i, is also returned. An error is raised if the first input is not a function handle. A warning is...
Write a subroutine that will receive a char input value. This subroutine should then use a...
Write a subroutine that will receive a char input value. This subroutine should then use a switch statement to determine if the char is a vowel, consonant, digit, or other type of character. Write the subroutine only,
Write a function in C that uses the Merge Sort sorting algorithm with arrays. The function...
Write a function in C that uses the Merge Sort sorting algorithm with arrays. The function must not be void and must output type int* i.e. it must take the form: int* merge_sort(int a[], int n) where a[ ] is the input matrix and n is the size of the matrix. You may use an auxiliary functions such as "merge." The returned array should be sorted using merge_sort and should not modify the array that was input (a[ ] ).
Write an MSP430 assembly language program that implements the following algorithm: a subroutine, called 'numadd' that...
Write an MSP430 assembly language program that implements the following algorithm: a subroutine, called 'numadd' that sums up all the numeric characters present in a phrase ("string" that follows the "C" language convention). By For example, if the phrase is "Today is the 28th of month 9", the subroutine must perform the following sum: 2 + 8 + 9 = 19. The subroutine must receive the address of the first character of the corresponding phrase in the "stack", and return...
Write an MSP430 assembly language program that implements the following algorithm: a subroutine, called ‘numadd’ that...
Write an MSP430 assembly language program that implements the following algorithm: a subroutine, called ‘numadd’ that sums up all the numeric characters present in a sentence (“string” that follows the “C” language convention). For example, if the phrase is "Today is the 21st of month 5", the subroutine must perform the following sum: 2 + 1 + 5 = 8. The subroutine must receive the address of the first character of the corresponding phrase in the " stack ”, and...
Write and test a merge function that uses a recursive algorithm to merge two sorted arrays...
Write and test a merge function that uses a recursive algorithm to merge two sorted arrays of integers. Neither list contains duplicates, and the resulting list should not contain duplicates either. Hint: You may want to call a helper function from merge. PROGRAM: C
Please use MATLAB. Write a program to plot the piecewise function using IF statements and a...
Please use MATLAB. Write a program to plot the piecewise function using IF statements and a FOR loop in MatLab. Use x as the input vector. Plot from -20<=x<=20, increment of 1.   y =   4 x + 10 ,             ? ≥ 9,                   y =      5? + 5,                   0 ≤ ? < 9,                    y =     ?2 + 6? + 8, ? < 0 Plot each segment of the fn with different shaped points and a different color, for...
MATLAB CODE: Making cubic spline iterpolation function. Then, To solve use Tridiagonal matrix algorithm(TDMA) xi -0.5...
MATLAB CODE: Making cubic spline iterpolation function. Then, To solve use Tridiagonal matrix algorithm(TDMA) xi -0.5 -0.4 -0.2 0 0.2 0.4 0.6 0.8 yi 0.04 0.1 0.4 1 0.35 0.2 0.3 0.04
Using MATLAB: The velocity, v, and the distance, d, as a function of time, of a...
Using MATLAB: The velocity, v, and the distance, d, as a function of time, of a car that accelerates from rest at constant acceleration, a, are given by = a n d = 12 Determine v and d at every second for the first 10 seconds for a car with acceleration of = 15 ft/s2. Your output must have exactly the same format as the template table below. Note that dots have been added to the table below; you can...
Write a matlab code for given task Use your ‘sin’ or ‘cos’ function to generate a...
Write a matlab code for given task Use your ‘sin’ or ‘cos’ function to generate a sinusoid wave having two components as f1 = 3kHz and f2 = 5kHz and then sample it with fs = 10kHz. Calculate its fft with zero frequency component in the middle. Plot it on a properly scaled w-axis. Specify if there is aliasing or not? If there is aliasing specify which component is casing the aliasing
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT