Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB Assignment#1 Write a MATLAB code that performs the function of (polynomia

ID: 3209886 • Letter: M

Question

MATLAB Assignment#1 Write a MATLAB code that performs the function of (polynomials' calculator and plotter of the nth order), so that the user can make the basic mathematical operations (+,-, *,/) on any number and any order of polynomials and can obtain the required plots, Knowing that, the user has to specify the order of that polynomials' calculator, i.e: for example (just an example): If the user specifies an order of n-3, then the maximum order of a polynomial that can be used in calculations is 3rd order then it's a 3rd order polynomials' calculator The code has to perform the following: Specify the maximum order of polynomials (order of calculator) -Make any number of calculations ( + ,-, * , / ) on polynomials entered by the user, and find the final result All input polynomials have to be plotted on the same graph on a domain [-2,2 Rled polynomial has to be plotted on a separate graph on a domain [-2,2]

Explanation / Answer

%% Function of exp(x) = sum(x^n/n!):n = 0 to infinity

% n = input('Enter the heightest order of polynomial');
n = 4 ;
x = -2:0.1:2;
pol_cal = zeros(n+1,length(x));   
pol_cal(1,:) = 1; % First constant term of polynomial
for k = 1:n
for ii=1:length(x)
pol_cal(k+1,ii) = x(ii)^k / factorial(k);
end
end
Height_Order_Pol = sum(pol_cal);
%% Plotting each order term plot
figure(1)
hold on; box on;
for ii=1:n+1
plot(x,pol_cal(ii,:));
end
legend('n = 0','n = 1','n = 2', 'n =3','n = 4')
%% Plotting of hightest order polynomial
figure(2)
hold on; box on;
plot(x,Height_Order_Pol);