Question

In: Computer Science

Write a MATLAB function, called arbpoly, that computes a polynomial arbitrary nth degree. The function will...

Write a MATLAB function, called arbpoly, that computes a polynomial arbitrary nth degree. The function will take 2 inputs:

1) the first input will be a row vector, c, containing the coefficients of the polynomial, starting with the coefficient of the highest - degree term;

2) the second input will be a scalar, x, which is a real number at which the polynomial will be evaluated.

The function's only output, y, will be the scalar value of the polynomial computed at the value of input x.

In the body of your function, use vector(s), not loops, to evaluate the polynomial. MATLAB's function (length) will come in handy.

Note that script that calls/test the functions are already provided.

%script that calls/tests the function arbpoly

%tests 1-5 not random

c = [-2 0 3 -4 5 0 1];

x1 = -3;

z1 = arbpoly(c,x1)

c = [0 -3 1 4 0 1 -5];

x2 = 2;

z2 = arbpoly(c,x2)

c = [0 0 0 1];

x3 = -3;

z3 = arbpoly(c,x3)

c = [0 0];

x4 = 2;

z4 = arbpoly(c,x4)

c = [9 0 0 0];

x5 = 2;

z5 = arbpoly(c,x5)

%test with a ranom vector for c

len = randi([1 10],1,1);

c = randi([-10 10], 1, len);

x6 = 2;

z6 = arbpoly(c,x6)

%tests with random vector for c and x

c = randi([-10 10], 1, 5);

x7 = randi([-10 10], 1, 10);

z7 = zeros(1,10);

for i = 1:10

z7(i) = arbpoly(c,x7(i));

end

z7'

%%% this will plot the function

%%% uses a loop for x values

c = [-2 3 0 1];

x8 = linspace(-1.5,2.5,200);

z8 = zeros(1,200);

for i = 1:200

z8(i) = arbpoly(c,x8(i));

end

plot(x8,z8)

Solutions

Expert Solution

`Hey,

Note: If you have any queries related to the answer please do comment. I would be very happy to resolve all your queries.

clc

clear all

close all

format long

%tests 1-5 not random

c = [-2 0 3 -4 5 0 1];

x1 = -3;

z1 = arbpoly(c,x1)

c = [0 -3 1 4 0 1 -5];

x2 = 2;

z2 = arbpoly(c,x2)

c = [0 0 0 1];

x3 = -3;

z3 = arbpoly(c,x3)

c = [0 0];

x4 = 2;

z4 = arbpoly(c,x4)

c = [9 0 0 0];

x5 = 2;

z5 = arbpoly(c,x5)

%test with a ranom vector for c

len = randi([1 10],1,1);

c = randi([-10 10], 1, len);

x6 = 2;

z6 = arbpoly(c,x6)

%tests with random vector for c and x

c = randi([-10 10], 1, 5);

x7 = randi([-10 10], 1, 10);

z7 = zeros(1,10);

for i = 1:10

z7(i) = arbpoly(c,x7(i));

end

z7'

%%% this will plot the function

%%% uses a loop for x values

c = [-2 3 0 1];

x8 = linspace(-1.5,2.5,200);

z8 = zeros(1,200);

for i = 1:200

z8(i) = arbpoly(c,x8(i));

end

plot(x8,z8)

function z=arbpoly(c,x)

z=zeros(size(x));

for i=1:length(c)

z=z.*x+c(i);

end

end

Kindly revert for any queries

Thanks.


Related Solutions

1] Find an​ nth-degree polynomial function with real coefficients satisfying the given conditions. If you are...
1] Find an​ nth-degree polynomial function with real coefficients satisfying the given conditions. If you are using a graphing​ utility, use it to graph the function and verify the real zeros and the given function value. n=​3; 2 and 5i are zeros; f(1) = 52 f(x)= ? ​(Type an expression using x as the variable. Simplify your​ answer.) 2] Find an​ nth-degree polynomial function with real coefficients satisfying the given conditions. If you are using a graphing​ utility, use it...
Find an nth-degree polynomial function with real coefficients satisfying the given conditions. If you are using...
Find an nth-degree polynomial function with real coefficients satisfying the given conditions. If you are using a graphing utility, use it to graph the function and verify the real zeros and the given function value. n= 4; -1,4, and 4+2i are zeros f(1)=-156
For the following exercises, use the graphs to write a polynomial function of least degree.
For the following exercises, use the graphs to write a polynomial function of least degree.
Write a MATLAB function [p, z] = proj(A,b) that computes the projection of b onto the...
Write a MATLAB function [p, z] = proj(A,b) that computes the projection of b onto the Column Space of an m × n matrix A. Your program should allow for the possibility that the columns of A are not linearly independent. In order for the program to work, you will need to create a basis for Col A.
Write a Matlab/SciLab function that accepts inputs as degrees and computes the equivalent within the interval...
Write a Matlab/SciLab function that accepts inputs as degrees and computes the equivalent within the interval 0 to 360. function de=equivalent(d) For example, equivalent(540) = 180 equivalent(-30) = 330
State whether the function is a polynomial function or not. If it​ is, give its degree....
State whether the function is a polynomial function or not. If it​ is, give its degree. If it is​ not, tell why not. 4(x-1)^12(x+1)^7
Write 2 MATLAB functions. One called exptrig which takes a vector of arbitrary length, x, containing...
Write 2 MATLAB functions. One called exptrig which takes a vector of arbitrary length, x, containing any real numbers, and computes the mathematical function f(x) = 3e^(-x)(cos^2(5x) - sin^2(5x)). The other one will be called trigsum, which takes a vector arbitrary length, x, containing any real numbers, and computes the mathematical function g(x)= ((sin(10x) + cos(10x))/ 2) + 3. Both functions will be computed at each of the values of x, and internally will output these values into a vector,...
A. Write a function in MATLAB called findTranspose that takes in as input any matrix or...
A. Write a function in MATLAB called findTranspose that takes in as input any matrix or any vector and simply returns back the transpose of that input. You can always verify your answer by using the inbuilt transpose function in MATLAB, however, you cannot use the transpose function directly when writing your code. Here is the starter code that we are providing to help you get started %x is the input vector or matrix. You can find the %size that...
Write a single MATLAB function called numdiff, saved in a file called numdiff.m. Submit that single...
Write a single MATLAB function called numdiff, saved in a file called numdiff.m. Submit that single file here in Canvas. To make grading easier, please do the following: • Close your function with "end". • Don't have your function print anything to the console; just return the output. To accomplish this: o Put a semicolon ";" at the end of each statement. o Put a percent "%" before each disp or fprintf statement. The function numdiff should take the following...
Using Matlab Write a function, called digits_function that is able to calculate the number of digits...
Using Matlab Write a function, called digits_function that is able to calculate the number of digits and the multiplication of the digits. The input of this function is N (entered number) and the outputs are number_digits and sum_digits.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT