# Quintic Polynomial    Solution

hw31.m

close all

clear

clc

fprintf(‘Enter coefficients for a quintic polynomial of the form:\n\ty = ax^5 + bx^4 + cx^3 + dx^2 + ex + f\n’);

a = input(‘Enter a value for a: ‘);

b = input(‘Enter a value for b: ‘);

c = input(‘Enter a value for c: ‘);

d = input(‘Enter a value for d: ‘);

e = input(‘Enter a value for e: ‘);

f = input(‘Enter a value for f: ‘);

fprintf(‘The quintic polynomial you have entered is:\n\ty = (%.3f)x^5 + (%.3f)x^4 + (%.3f)x^3 + (%.3f)x^2 + (%.3f)x + (%.3f)\n’,a,b,c,d,e,f);

x = zeros(1,5);

y = zeros(1,5);

for i = 1:5

x(i) = input(‘Enter a value for x: ‘);

y(i) = a*x(i)^5 + b*x(i)^4 + c*x(i)^3 + d*x(i)^2 + e*x(i) + f;

end

T = [‘x      ‘     ‘y(x)’];

disp(T);

fprintf(‘\n’);

for i = 1:5

fprintf(‘%.2f   %.2f\n’, x(i),y(i));

end

xs = min(x):0.01:max(x);

ys = a*xs.^5+b*xs.^4+c*xs.^3+d*xs.^2+e*xs+f;

figure(1)

hold on

plot(xs,ys,’b’,’LineWidth’,2);

plot(x,y,’+r’,’LineWidth’,2);

legend(‘QuinticPolynomial’,’Entered values’,’Location’,’NorthWest’)

hw32.m

close all

clear

clc

N = input(‘Enter a value for N: ‘);

if (N <0 || floor(N) ~= N)

while(N <0 || floor(N) ~= N)

if (N < 0)

fprintf(‘You have entered a negative number which is not allowed.\n’);

else

fprintf(‘You have entered a positive number but it must be an integer.\n’);

end

N = input(‘Enter a new value for N: ‘);

end

end

fact = 1;

for i = 1:N

fact = fact*i;

end

fprintf(‘\n %d! = %d\n’,N,fact);