Signature & Exponent

Solution

exp_to_5.m

%Returns input raised to exponent 5

function y = exp_to_5(x)

y = x*x*x*x;

exp_to_11.m

%Returns input raised to exponent 11

function y = exp_to_11(x)

% 11 can be written as 8 + 2 + 1. I defined three variables to find x^11

a = x;

b = x;

c = x;

a = a*a;

a = a*a;

a = a*a;

b = b*b;

y = a*b*c;

exp_to_16_1.m

%Returns input raised to exponent 16

function y = exp_to_16_1(x)

x = x*x;

x = x*x;

x = x*x;

x = x*x;

y = x;

exp_to_16_2.m

%Returns input raised to exponent 16

function y = exp_to_16_2(x)

y = x^16;

exp_to_neg_3_1.m

%Returns input raised to exponent negative 3

function y = exp_to_neg_3_1(x)

y = 1/(x*x*x)

exp_to_neg_3_2.m

%Returns input raised to exponent negative 3

function y = exp_to_neg_3_2(x)

y = x^(-3);

mult_by_5.m

% Multiply by 5

function y = mult_by_5(x)

y = x + x + x + x + x;

mult_by_16_1.m

% Multiply by 16

function y = mult_by_16_1(x)

y = x+x+x+x+x+x+x+x+x+x+x+x+x+x+x+x;

mult_by_16_2.m

% Multiply by 16

function y = mult_by_16_2(x)

x = x+x;

x = x+x;

x = x+x;

x = x+x;

y = x;

mult_by_16_3.m

% Multiply by 16

function y = mult_by_16_3(x)

y = 16*x;

mult_by_512.m

% Multiply by 512

function y = mult_by_512(x)

x = x+x;

x = x+x;

x = x+x;

x = x+x;

x = x+x;

x = x+x;

x = x+x;

x = x+x;

x = x+x;

y = x;

mult_by_1000.m

function y = mult_by_1000(x)

%1000 can be written as 10*(64+32+4). We will use doubling technique to find

%64 times x ,32 times x and 4 times x and then we will add it ten times.

% double 6 times to get 64*x

a = x;

a = a+a;

a = a+a;

a = a+a;

a = a+a;

a = a+a;

a = a+a;

% double 5 times to get 32*x

b = x;

b = b+b;

b = b+b;

b = b+b;

b = b+b;

b = b+b;

% double 2 times to get 4*x

c = x;

c = c+c;

c = c+c;

% sum all three terms

z = a+b+c;

% add ten times to get 1000*x

y = z+z+z+z+z+z+z+z+z+z;

mult_by_neg_5.m

% Multiply by negative 5

function y = mult_by_neg_5(x)

y = -(x+x+x+x+x);