Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
48 views8 pages

% Name: Song Yiheng % ID: 29275873 % Date Created: Aug 23 %% Lab 4 Task1 % Prompt User To Input The Shape They Want To Choose

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 8

% Name: Song Yiheng

% ID: 29275873
% Date created: Aug 23
clear all; clear all; clc;
%% Lab 4 Task1
% prompt user to input the shape they want to
choose
fprintf('Shapes(ID Number):
\n1.Square\n2.Rectangle\n3.Circle\n----------------
--------\n')
shape = input('Input the wanted shape(ID
Number):');

% Square
if shape == 1
square_sidelength = input ('Enter the side
length of the square:');
square_area = square_sidelength *
square_sidelength;
fprintf('--------\nThe area of the square
is %.2f',square_area)
% Rectangle shape
elseif shape == 2
rectangle_width = input('Enter the width of the
rectangle:')
rectangle_height = input('Enter the height of
the rectangle:')
rectangle_area = rectangle_width *
rectangle_height;
fprintf('--------\nThe area of the rectangle
is %.2f', rectangle_area)
elseif shape == 3
circle_radii = input('Enter the radii of the
circle:')
circle_area = pi*cicle_radii*circle_radii;
fprintf('--------\nThe area of the circle
is %.2f', circle_area)
end
function n_fac = stirling_appro(n)

n_fac = (sqrt(2*pi*n))*((n/exp(1))^n);

% Name: Song Yiheng


% ID: 29275873
% Date created: Aug 23
% Function file for task
% n is an input argument

% Name: Song Yiheng


% ID: 29275873
% Date created: Aug 23
clear all; clear all; clc;
%% Lab 4 Task 2
% Enter value of n
n = input('Enter an Integer Number: ');

%Call the function


n_fac = stirling_appro(n);
nfac_round = round(n_fac);

%If Statement
if mod(nfac_round,2)==0 && mod(nfac_round,3)~=0 &&
mod(nfac_round,7)~=0
nfac_str = 'divisible by 2 only but not
divisible by 3 and 7';
elseif mod(nfac_round,3)==0 && mod(nfac_round,2)~=0
&& mod(nfac_round,7)~=0
nfac_str = 'divisible by 3 only but not
divisible by 2 and 7';
elseif mod(nfac_round,7)==0 && mod(nfac_round,3)~=0
&& mod(nfac_round,2)~=0
nfac_str = 'divisible by 7 only but not
divisible by 2 and 3';
elseif mod(nfac_round,2)==0 && mod(nfac_round,3)==0
&& mod(nfac_round,7)~=0
nfac_str = 'divisible by 2 and 3 but not
divisible by 7';
elseif mod(nfac_round,2)==0 && mod(nfac_round,7)==0
&& mod(nfac_round,3)~=0
nfac_str = 'divisible by 2 and 7 but not
divisible by 3';
elseif mod(nfac_round,3)==0 && mod(nfac_round,7)==0
&& mod(nfac_round,2)~=0
nfac_str = 'divisible by 3 and 7 but not
divisible by 2';
elseif mod(nfac_round,2)==0 && mod(nfac_round,3)==0
&& mod(nfac_round,7)==0
nfac_str = 'divisible by 2,3 and 7';
elseif mod(nfac_round,3)~=0 && mod(nfac_round,2)~=0
&& mod(nfac_round,7)~=0
nfac_str = 'not divisble by 2, 3 and 7';
end

fprintf('The n value is %.0f and its approximated


factorial is %f and its rounded number
is %s.\n',n,n_fac,nfac_str)
% Name: Song Yiheng
% ID: 29275873
% Date created: Aug 23
clear all; clear all; clc;
%% Lab 4 Task 3
% Extract value from txt file
filename=('temperatures.txt');
fid=fopen(filename,'r');
row1 = fgetl(fid);
fclose(fid);
temp = str2num(row1);

%% Plot temperature against day


d = linspace(1,50,50);
figure(1)
plot(d,temp,'rdiamond')
xlabel('Day')
ylabel('temperature')
title('Temperature against Time')
hold on

%% Elimate noisy data


index = (temp>0 & temp<45);
Temp = temp(index);
day = d(index);
% Plot and label
figure(2)
plot(day,Temp,'bo')
xlabel('Day')
ylabel('Temperature')
legend('Valid Temperatures Values against the
Corresponding Valid Time')
% Name: Song Yiheng
% ID: 29275873
% Date created: Aug 23
clear all; clear all; clc;
%% Lab 4 Task 4
P = linspace(1,8,8);
W = [95 45 76 88 51 50 61 105];
H = [1.87 1.6 1.72 1.61 1.5 1.61 1.58 1.83];
BSA = 0.007184*(W.^0.425).*(H.^0.725);

filename='BSA.txt';

file_id=fopen(filename,'W');
fprintf(file_id,'BSA value of each person\n');
fprintf(file_id,'%10s %10s %10s %10s\n','Person#','
Mass(kg)','Height(m)','BSA');
fprintf(file_id,'%10.2f %10.2f %10.2f %10.2f\n',[P'
W' H' BSA']');
fclose(file_id);
% Name: Song Yiheng
% ID: 29275873
% Date created: Aug 23
clear all; clear all; clc;
%% Lab 4 Task 5
% Import the data
X = importdata('ENG1060studentmarks.txt');
num_data = X.data;
ID = num_data(:,1);
lab_mark = num_data(:,2:11);
assignment1 = num_data (:,12);
lab = sum(lab_mark')/10*2;
assignment = assignment1';

% Call out function


[internalmarks] = internalgradecalc
(lab,assignment);

% Ask to input ID number


index = input('Enter your ID number: ');

% Creating an if statement for determining the


internal mark
if index==ID(1,1);
mark = internalmarks(1,1);
elseif index==ID(2,1);
mark = internalmarks(1,2);
elseif index==ID(3,1);
mark = internalmarks(1,3);
elseif index==ID(4,1);
mark = internalmarks(1,4);
elseif index==ID(5,1);
mark = internalmarks(1,5);
elseif index==ID(6,1);
mark = internalmarks(1,6);
elseif index==ID(7,1);
mark = internalmarks(1,7);
elseif index==ID(8,1);
mark = internalmarks(1,8);
elseif index==ID(9,1);
mark = internalmarks(1,9);
elseif index==ID(10,1);
mark = internalmarks(1,10);
elseif index==ID(11,1);
mark = internalmarks(1,11);
elseif index==ID(12,1);
mark = internalmarks(1,12);
elseif index==ID(13,1);
mark = internalmarks(1,13);
elseif index==ID(14,1);
mark = internalmarks(1,14);
elseif index==ID(15,1);
mark = internalmarks(1,15);
elseif index==ID(16,1);
mark = internalmarks(1,16);
elseif index==ID(17,1);
mark = internalmarks(1,17);
elseif index==ID(18,1);
mark = internalmarks(1,18);
elseif index==ID(19,1);
mark = internalmarks(1,19);
elseif index==ID(20,1);
mark = internalmarks(1,20);
end

% Print to the command window


fprintf('Student ID: %.0f\nYour internal marks
is %.2f%%.\n',index,mark);

function [internalmarks] = internalgradecalc


(lab,assignment)
internalmarks = lab+assignment;
% Name: Song Yiheng
% ID: 29275873
% Date created: Aug 23
% Function file for task 5 which calculate the
internal marks by adding lab
% marks and assignment marks

You might also like