CMCA Assignment: Computational Mathematics & Architecture MATLAB

Verified

Added on  2023/06/09

|7
|541
|138
Homework Assignment
AI Summary
This assignment solution provides MATLAB codes for various computational mathematics and computer architecture problems. It includes code for currency exchange, finding prime numbers, identifying perfect numbers, determining Armstrong numbers, and generating graphs for x, y, and z coordinates. The currency exchange code converts Singapore Dollars (SGD) to US Dollars (USD), British Pounds (GBP), and Euros using specified conversion rates. The prime number code identifies prime numbers within a given range. The perfect number code searches for perfect numbers within a specified range. The Armstrong number code checks if a number is an Armstrong number. Finally, the graphing code generates plots for x-y, x-z, and x-y-z coordinates. The document includes MATLAB code snippets and corresponding outputs, demonstrating the implementation and results of each problem.
Document Page
Running Head: COMPUTATIONAL MATHEMATICS AND COMPUTER ARCHITECTURE
0
COMPUTATIONAL MATHEMATICS AND COMPUTER ARCHITECTURE
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
COMPUTATIONAL MATHEMATICS AND COMPUTER ARCHITECTURE
1
Currency Exchange
MATLAB Code
clc;
clear all;
close all;
toGBP = 0.56; toEuro = 0.64; toUsd = 0.72;
SGD = (1:25)';
USD = SGD.*toUsd;
EURO = SGD.*toEuro;
GBP = SGD.*toGBP;
data = table(SGD, USD, GBP, EURO);
disp(data)
Output
Document Page
COMPUTATIONAL MATHEMATICS AND COMPUTER ARCHITECTURE
2
Prime Number
MATLAB Code
clc;
clear all;
close all;
x1 =input('Enter first value = ');
x2 =input('Enter second value = ');
i = x1:x2 ;
p = isprime(i);
disp('prime numbers are =');
i(p)
Output
Perfect number
MATLAB Code
clc;
clear all;
Document Page
COMPUTATIONAL MATHEMATICS AND COMPUTER ARCHITECTURE
3
x1 =input('Enter first value ');
x2 =input('Enter second value ');
perfect = zeros(1,x2);
for n = x1:x2
if true
% code
end
test = 1:n-1;
if (sum(test(mod(n,test) == 0)) == n)
perfect(n) = n;
end
end
perfect(perfect == 0) = []
Output
Armstrong Number
MATLAB Code
clc;
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
COMPUTATIONAL MATHEMATICS AND COMPUTER ARCHITECTURE
4
x1 = input('Please input the first number: \n');
x2 = input('Please input the second number: \n');
for (value = x1:x2)
numstr = num2str(value);
i = 0;
for (digit = 1:length(numstr))
digitcube = str2num(numstr(digit)) ^ 3;
i = i + digitcube;
end
if (i == value)
fprintf('%d is an armstrong number. \n', value)
end
end
Output
Graph for x, y, and z
MATLAB Code
clc;
clear all;
x = 0:pi/100:20*pi;
y = x.*sin(x);
z = x.*cos(x);
Document Page
COMPUTATIONAL MATHEMATICS AND COMPUTER ARCHITECTURE
5
figure
plot(x,y)
xlabel('Axis for X');
ylabel('Axis for Y');
title('Graph in X-Y direction');
figure
polar(x,z)
xlabel('Axis for X');
ylabel('Axis for Z');
title('Graph in X-Z direction');
figure
plot(x,y,z)
xlabel('Axis for X');
ylabel('Axis for Y');
zlabel('Axis for Z');
title('Graph in X,Y,Z direction');
For x-y
Document Page
COMPUTATIONAL MATHEMATICS AND COMPUTER ARCHITECTURE
6
For x-z
For X, Y, and Z
chevron_up_icon
1 out of 7
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]