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);
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 :
MATLAB Only MATLAB Only MATLAB Only Indicated in the script below, write a function, called arbpoly3,...
MATLAB HELP PLEASE
Write a Matlab function that evaluates a sum of sines at a set of points. The first term is just a constant (a coefficient with no sine term). Then, each sine term will have a coefficient before it and then an increasing multiple of the angle inside. For example, consider the sum 3 + 4 sin(9)-1.5 sin (20) 2 sin (40)3 sin (50) We recognize that this is the same as 344sin(101+-1.5 sin (20) + 0 sin...
Matlab: Write a function called minimax that takes M, a matrix input argument and returns mmr, a row vector containing the absolute values of the difference between the maximum and minimum valued elements in each row. As a second output argument called mmm, it provides the difference between the maximum and minimum element in the entire matrix. See the code below for an example: >> A = randi(100,3,4) A = 66 94 75 18 4 68 40 71 85 76...
MATLAB Problem
HW7P2 (20 points) (5 pts) Write a user-defined MATLAB function called HW7P2_fn for the following math function 3 o-0.47x The input to the function is x and the output is y. Write the function such that x can be an array (use element-by-element operations) (15 pts) Use the function in (a) the command window to calculate y(-2) and y(5) (b) a script file HW7P2.m to determine y(x) for 0.001 Sx S 10 with 1000 points. Hint: Use the...
I just need some matlab help and assistance
Refresher 1. Create a vector called A containing 1, 2, 3,4, and 5 2. Create a vector called B containing 6,7, 8, 9, and 10 . Combine A and B to create an array called C where A is the first row and B is the second row 4. Find the 7th element in C 5. Determine the location of 8' in array C
The problem demonstrates the use of the random number generator to recover previously generated random numbers Write a function called randi test that takes two scalar positive integer arguments maxi and n, and retums two output arguments: a row vector of n2 elements and and n-by-n matrix. The two output arguments must contain the exact same set of random integers that fall between 1 and maxi Do this using the random number genertor, not by reshaping the data Example n,v-randi...
MATLAB ASSIGMENT 1. A. Create a function called ch16initials3 Input: row vector of 101 values (Note: input values are specified in the function call) Output: calculated maximum value Create a row vector A of values from 50 down to 0, with an increment of 0.5 Multiply the elements of A and the square of the elements of the input vector Store the results in B Find the maximum value of B and store it in C – this is the...
[MATLAB] Write a function called myMultProd.m that computes the cumulative product of the elements in a vector. The cumulative product, pj, of the jth element of the vector x, xj, is defined by pj = (x1)(x2) … (xj) for j = 1:length of the vector x. DO NOT USE CUMPROD For example, when you run your function it should look like this: >> x = [2 3 4 2]; >> myMultProd(x) >> ans = 2 6 24 48 That is,...
Using MatLab Write a function called PrimeFinder that receives an integer n as an input argument, and provides an output argument called Primes that is a vector containing all prime numbers between 2 and n, inclusive. Verify the correctness of your code with inserting 13 as the input argument, and check that your output is Primes = [2,3,5,7,11,13]. You are NOT allowed to use any directly relevant MATLAB built-in function such as divisors, etc. NOTE: A prime number is a...
MatLab Help!!
Write a function called Difference to calculate the central difference, forward diflerence, and backward diference approximation to an function within a given range of xmin:xinc:xmax The input argument of the function Difference is the handle to an anonymous function, a row array xmin:xinc:xmax The differences should be returned as a row array, calculated at xmin xinc xmax Restriction. The function should not use loops Ex func - (x) x.3 xmin-3 xinc-e.25; xmax-4; [backDifference, centralDifference, forwardDifference] Derivative(func, xmin, xmax,...
Write a matlab script(using only matlab) for this.
Write a script to solve the following problem: Ask the user for the length and the width of a rectangle. These need to be passed to a function. The function is to calculate and return the area and the perimeter of the rectangle. The area is the length times the width and the perimeter is 2 times the length and 2 times the width. Make sure to suppress all output from the...