Free sample   Computational mathematics assignment mathematical problems based on computer architecture

## Computational Mathematics Assignment: Mathematical Problems Based On Computer Architecture

Question

Question 1
(a) Convert 1100 10012 to the following formats. In this part of computational mathematics assignment, show your working clearly:
a. Decimal
b. Octal

a. 11001001 to decimal
110010012=(1×27)+(1×26)+(0×25)+(0×24)+(1×23)+(0×22)+(0×21)+(1×20)110010012=(1×27)+(1×26)+(0×25)+(0×24)+(1×23)+(0×22)+(0×21)+(1×20)

11001001=128+64+0+0+8+0+0+1
11001001=128+64+0+0+8+0+0+1

110010012=20110

b. 11001001 to octal
Split the binary number from left to right each group 4 bits
1100 1001
C 9
110010012=C916

(b) Evaluate the following expressions. Show your working clearly: a. 11002 * 10112

Solution:

1 1 0 0
× 1 0 1 1
________________________________________
1 1 0 0
1 1 0 0 0
1 1 0 0 0 0 0
________________________________________
1 0 0 0 0 1 0 0

b. 7478 + 3508
Solution:

2 1 2
4 3 4
7 4 7
× 3 5 0
________________________________________
4 6 0 3 0
2 6 6 5 0 0
________________________________________
3 3 4 5 3 0

Answer=3 3 4 5 3 0

c. 0xACE + 0xCAFE
Solution:

8 9 A
6 8 8
A C D
9 B C
A C E
× C A F E
________________________________________
9 7 4 4
A 2 1 2 0
6 C 0 C 0 0
8 1 A 8 0 0 0
________________________________________
8 9 1 4 4 6 4

(c) Binary Converter Program - Write a program to accept a single binary number of up to 8 bits and display the equivalent in decimal.

decimal = 0; %decimal
reminder=0; %reminder
pow=0; %power
flag=0;
binary = input('Enter binary number (in form of 0 and 1): ', 's'); % read
if length(binary)>8 % if length >8 display wrong input
disp('Wrong input upto 8 digit allowed');
else
num=str2num(binary); %convert to number
while num ~= 0 %num not equal to 0
reminder = mod(num,10); %find reminder
if reminder>1
flag=1; % set flag value and break
break;
end
num = round(num/10); % divide by 10
decimal = decimal + reminder * 2^(pow); % find decimal
pow=pow+1;

end
if flag==1
fprintf('Wrong input number in binary, not possible to find a decimal value');
else
fprintf('decimal value =%d\n',decimal);
end
end

Question 2
(a) Given the following matrices

???? =
Evaluate the following, showing your steps clearly.
i. A + B
A + B =
3 0
1 2

ii. 3 (A – B)
(A-B)=
1 -4
5 -12
3(A-B)=
3 -12
15 -36

iii. 2A * C
2A=
4 -4
6 -10 iv. Show that A * I = A where I is the identity matrix v. Prove that A * B is not equal to B * A

A*B= B*A= (b) Matrix Processing Program - Write a program to accept a 2 x 4 matrix from user input and find the following:
a. Maximum element in the 2 x 4 matrix
b. Minimum element in the 2 x 4 matrix
c. Average of all elements in 2 x 4 matrix
d. Sorted in a single array of elements

clear all
m=input('Enter the number of rows:');
n=input('Enter the number of colums:');
for i=1:m
for j=1:n
a(i,j)=input('Enter the elements:');
end
end
%program to display matrix
a = reshape(a,m,n)
disp('Maximum element in each column:');
max(a)
disp('Minimum element in each column:');
min(a)
disp('Maximum element of all elements for the entire matrix:');
max(max(a))
disp('Minimum element of all elements for the entire matrix:'); min(min(a))
disp('Average element of all elements for the entire matrix:'); mean(mean(a))
%converting 2-d matrix to 1-d array
A = a(:);
%sorting 1-d array
disp('Sorted 1-d array:');
sort(A)

Question 3

Given an expression
?????(???? + ????) + (???? + ????. ????)(???? + ?????) + ???? + ????. ????

(a) Draw the Boolean logic circuitry (b) Construct the truth table for the above expression (c) Simplify the Boolean expression.

X’(X+Y)+ (Y+X.X)(X+Y’)+Z+X.Z
Applying Idempotent law,
=>X'(X+Y)+(Y+X)(X+Y')+Z+X.Z
Applying Absorption law,
=>X'(X+Y)+(Y+X)(X+Y')+Z
Applying Distributive Law,
=>X.X'+X'.Y+(Y+X)(X+Y')+Z
Applying Complement,
=>X'.Y+(Y+X)(X+Y')+Z
Applying Distributive Law,
=>X'.Y+Y(X+Y')+X(X+Y')+Z
Applying Distributive Law,
=>X'.Y+Y.X+Y.Y'+X(X+Y')+Z
Applying Complement,
=>X'.Y+Y.X+X(X+Y')+Z
Applying Distributive law
=>Y(X'+X)+X(X+Y')+Z
Applying Complement,
=>Y+X(X+Y')+Z
Applying Distributive law
=>Y+X.X+X.Y'+Z
Applying Idempotent law
=>Y+X+X.Y'+Z
Applying Absorption law,
=>Y+X+Z Or, X+Y+Z

Question 4
Complete the following programs given in the computational mathematics assignment:

a. Driving Academy App - Write a program that ask for your age to determine the eligibility to learn theory or driving in the driving academy.
a. If your age is below 18, output is “You can only learn theory from age 18 onwards”.
b. If age is between 18 and 21, output is “You can only learn theory at this time”.
c. If the age is above 21, output is “You can learn driving provided you have passed your theory."

age = input('Enter your age = ');
if age < 18
sprintf('You can only theory from age 18 onwards.')
elseif age>=18 && age <=21
sprintf('You can only theory at this time.')
else
sprintf('You can learn driving provided you have passed your theory.')
end

b. Children Incentive Program - Write a program to determine the incentive from government X depending on the person’s number of children.
a. If the person has 1 child, bonus is \$100.
b. If the person has 2 children, bonus is \$300.
c. If the person has 3 or 4 children, the bonus is \$500.
d. If the person has more than 4 children, the bonus is \$1000. Print the bonus the person should receive. Request for input again until the user chooses to quit with a negative input for the children.

while num>=0
%getting user input
prompt='Enter number of children:';
num=input(prompt);
if num<0
break;
elseif num == 0
format='For %d children, No Bonus\n';
fprintf(format,num)
elseif num==1
bonus=100;
format='For %d children, Bonus is \$%d\n';
fprintf(format,num,bonus)
elseif num==2
bonus=300;
format='For %d children, Bonus is \$%d\n';
fprintf(format,num,bonus)
elseif num==3 | num== 4
bonus=500;
format='For %d children, Bonus is \$%d\n';
fprintf(format,num,bonus)
else
bonus=1000;
format='For %d children, Bonus is \$%d\n';
fprintf(format,num,bonus)
end,
end

c. Lucky Draw Game - Write a program that randomly generates a set of 7 winning numbers ranging from 1 to 30. The user will then be asked to key in 3 numbers.
a. If all the 3 numbers are part of the winning numbers, display “Congratulations, you win!”
b. If the entries are not part of 7 winning numbers, display the “missed” numbers. For example, if the user keys in 1, 2, 3 and the winning numbers contain 1, 5, 6, 7, 8, 9, 10. The message displayed will be “Sorry, you missed on numbers: 2 3”
c. If the user does not win the game, the game is restarted and a new set of random numbers is generated again.

won = false;
while ~won
fprintf('Welcome to the Lucky Draw Game\n');
% Generate 7 random numbers between 1 and 30
winningNumbers = randi(30, 1, 7);
% Get 3 numbers from the user
n = [0 0 0];
n(1) = input('Enter first number: ');
n(2) = input('Enter second number: ');
n(3) = input('Enter third number: ');

% Check if all three numbers are present in winningNumbers or not
isPresent = ismember(n, winningNumbers);
% If all three are present then the user won
if isPresent(1) && isPresent(2) && isPresent(3)
won = true;
fprintf('Congratulations, you win!');
else
fprintf('Sorry, you missed on number(s): ');
% Print missed numbers
for i = 1:length(n)
if ~isPresent(i)
fprintf('%d ', n(i));
end
end
end
fprintf('\n\n');
end

Question 5
Smart Plotter Program - Design an application that displays a menu to ask the user to choose whether to:

a. Plot a graph from inputting values for both x and y axes or to
b. Load a file to plot the graph.
c. Quit the Smart Plotter

The user can choose then proceed to plot a simple 2D line, a scatter plot or a pie chart. The program will continue displaying the menu to allow the user to choose until the user chooses to quit the application.

choice = -1;
while(choice ~= 0)
disp('(1) Plot a graph from the entered x and y values')
disp('(2) Load a file to plot the graph')
disp('(0) Quit the Program')
% entering the choice from the user
choice = input('Please enter the choice: ');

% if choice is 1
if(choice == 1)
% input the x and y values manually from user
x = input('Please enter the x vector: ');
y = input('Please enter the y vector: ');
% displaying the x and y values to console
fprintf('x = ');
fprintf('%d ', x);
fprintf('\n')
fprintf('y = ');
fprintf('%d ', y);
fprintf('\n')

% if choice is 2, get the filename from user to read x and y values
elseif(choice == 2)
filename = input('Please enter the filename which contains x and y values: ', 's');
% checking if file exist or not
if(exist(filename, 'File'))
% extracting the column vectors as x and y values
x = data(:,1);
y = data(:, 2);
% displaying the x and y values to console
fprintf('x = ');
fprintf('%d ', x);
fprintf('\n')
fprintf('y = ');
fprintf('%d ', y);
fprintf('\n')
% calling the function displayMneu2() to plot the data
else
end
% else if choice is 0 terminate and exit
elseif(choice == 0)
disp('*** GoodBye ... ***')
else
% else if any other option is given then display the error message
disp('*** Please enter a valid option from 0 to 2 ***')
end
end

% Function to get the x and y values and plot the data by
% displaying the type of plot to be plotted

choice = -1;
% loop till choice is invalid
while(choice < 0 || choice > 3)
% show the menu to the user
disp('Please choose the type of plot')
disp('(1) 2D Line Plot')
disp('(2) Scatter Plot')
disp('(3) Pie Chart')
disp('(0) Return')
% input the choice for the type of plot
choice = input('Please enter the options: ');
% if choice is 1 then plot 2d line<

if(choice == 1)
figure;
plot(x, y,'-r*', 'LineWidth', 2)
title('2D Line Plot, X vs Y')
xlabel('x ->')
ylabel('y ->')
choice = -1; % set choice to -1 to continue looping
% if choice is 2 then plot scatter plot

elseif(choice == 2)
figure;
p = scatter(x, y);
p.LineWidth = 2;
p.MarkerEdgeColor = 'r';
title('Scatter Plot, X vs Y')
xlabel('x ->')
ylabel('y ->')
choice = -1; % set choice to -1 to continue looping
% if coice is 3 then plot as pie chart
elseif(choice == 3)
figure;
pie(y);
title('Pie Chart, Y')
choice = -1; % set choice to -1 to continue looping
% if choice is 0 then return from the function
elseif(choice == 0)
return;
else
% else display the error message
disp('*** Error! Please enter a valid options from 0 to 3 ***')
end
end
end

NEXT SAMPLE

#### Related Samples   #### FREE PARAPHRASING TOOL   #### FREE PLAGIARISM CHECKER   #### Other Assignment Services #### FREE WORD COUNT AND PAGE CALCULATOR  