Question

MATLAB Only MATLAB Only MATLAB Only Indicated in the script below, write a function, called arbpoly3,...

MATLAB Only MATLAB Only MATLAB Only

Indicated in the script below, write a function, called arbpoly3, that accepts two inputs:

i) a row vector, called c, containing the coefficients of the polynomial, starting with the coefficient for the lowest degree term, which is the constant term.

ii) a row vector, called x, which is the set of real numbers where the polynomial is to be evaluated.

The output, y, will be a vector containing the values of the polynomial, evaluated at the corresponding values in x; the dimensions of x and y will be equal. Your function will compute the polynomial using two nested for loops instead of vectors. Inside the loops, only arithmetic operations can be used and no function calls (nor ^) can be used.

%this code segment tests the function, arbpoly3, which you will write below

c = [1 2 3];

x = [1 2 3];

z1 = arbpoly3(c,x);

c = [1 0 2 0 3];

x = [-5 0 5 10];

z2 = arbpoly3(c,x);

c = [0 -2 3 0];

x = linspace(1,20,200);

z3 = arbpoly3(c,x);

c = [0 0 0 0];

x = [-10 -8 -6 -4 -2 0];

z4 = arbpoly3(c,x);

c = [-1 0 2 -4 2 0 0 0 20];

x = -5;

z5 = arbpoly3(c,x);

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

randstart = randi([-5 5]);

x = linspace(randstart,randstart+10,200);

z6 = arbpoly3(c,x);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

THE CODE FOR THE ABOVE QUESTION IS (solved in MATLAB R2018b):

function y = arbpoly3(c,x)
lengthOfC = size(c,2);
lengthOfX = size(x,2);
y = zeros(1,lengthOfX);
  
for i = 1:lengthOfX
temp = 0;
for j = 1:lengthOfC
temp = temp + (c(j) * (x(i) ^ (j-1)));
end
y(i) = temp;
end
end

SCREENSHOT OF CODE :

OUTPUT USING THE CODE SEGMENT PROVIDE IN THE QUESTION :

Add a comment
Know the answer?
Add Answer to:
MATLAB Only MATLAB Only MATLAB Only Indicated in the script below, write a function, called arbpoly3,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT