Use Matlab Code anxn + (30pts) Given a polynomial P(x) a) 1) + aix + ao Write a
ID: 3184620 • Letter: U
Question
Use Matlab Code
anxn + (30pts) Given a polynomial P(x) a) 1) + aix + ao Write a MATLAB function that takes in the coefficients of P(x) and outputs the coefficients of its derivative P'(x). b) Test and validate your MATLAB function with P(x) =-6x5 + 3x + 2. c) Write a MATLAB function that takes in the coefficients of P(x) along with the end points a andb and outputs the value of the integral P(x)dx d) Test and validate your MATLAB function with P(x--6x5 + 3x + 2 , a =-2, b = 1. e) Write a MATLAB function that takes in the coefficients of P(x) along with the values x and y and outputs the coefficients of the solution yéc to the differential equationx) where y, - (xo). Test and validate your MATLAB function with P(x) =-6x5 + 3x + 2 , xo--1 and yo = 3· f)Explanation / Answer
matlab code
close all
clear
clc
y = [-6 0 0 0 3 2];
y_c = coeff(y);
disp('Result of part (b):');
disp(y_c);
a = -2; b = 1;
res = calc_int(y,a,b);
disp('Result of part (d):');
disp(res);
% For parts (a) & (b)
function y_c = coeff(y)
% y = [an an-1 an-2 ... a1 a0];
y_c = zeros(1,length(y)-1);
for i=1:length(y)-1
y_c(i) = y(i)*(length(y)-i);
end
end
% For parts (c) & (d)
function res = calc_int(y,a,b)
% y = [an an-1 an-2 ... a1 a0];
y_c = zeros(1,length(y));
res = 0;
for i=1:length(y)
y_c(i) = y(i)/(length(y)-i+1);
res = res + y_c(i)*(b^(length(y)-i+1) - a^(length(y)-i+1));
end
end
output
Result of part (b):
-30 0 0 0 3
Result of part (d):
64.5000
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.