MATLAB Code1

3
MATLAB Code: Output: %File name: Lab1.m % % Purpose: To perform some trivial calculations and quit MATLAB % files % %Date Programer Description %++++++++++ +++++++++++ ++++++++++++++ %01/28/2015 Alex Richey Lab 1 problems % %% Problem 1 % Purpose:To convert Fahrenheit to Celsius ftemp = input('Enter the temperature in F' ); % Get the temperature in F ctemp = (ftemp-32)*5/9; % Convert the temperature from F to C Enter the temperature in F 80 The converted temperature in Celcius is 26.666667.

description

Code for matlab

Transcript of MATLAB Code1

Page 1: MATLAB Code1

MATLAB Code:

Output:

%File name: Lab1.m%% Purpose: To perform some trivial calculations and quit MATLAB% files%%Date Programer Description%++++++++++ +++++++++++ ++++++++++++++%01/28/2015 Alex Richey Lab 1 problems%%% Problem 1% Purpose:To convert Fahrenheit to Celsiusftemp = input('Enter the temperature in F' ); % Get the temperature in Fctemp = (ftemp-32)*5/9; % Convert the temperature from F to Cfprintf('The converted temperature in Celcius is %f. \n',ctemp)

Enter the temperature in F 80

The converted temperature in Celcius is 26.666667.

Page 2: MATLAB Code1

Matlab Code:

Output:

%File name: Lab1.m%% Purpose: To perform some trivial calculations and quit MATLAB% files%%Date Programer Description%++++++++++ +++++++++++ ++++++++++++++%01/28/2015 Alex Richey Lab 1 problems%

%% Problem 2% Purpose: To Generate random numbersrandom_real = rand*(50-20)+20 %Generate a random real number between 20 and 50random_integer = randi([50,100], 1) %Generate a random intager between 50 and 100

random_real = 23.8096

random_integer = 96

Page 3: MATLAB Code1

Matlab Code:

Output:

%File name: Lab1.m%% Purpose: To perform some trivial calculations and quit MATLAB% files%%Date Programer Description%++++++++++ +++++++++++ ++++++++++++++%01/28/2015 Alex Richey Lab 1 problems%%% Problem 3% Purpose: To compute weight tolerance weight = input('Enter the desired weight: '); %To find the weighttolerance = input ('Enter the desired tolerance: '); % To find the toleranceweight_min = weight - (.01*tolerance*weight) %To find the minimum weightweight_max = weight + (.01*tolerance*weight) %To find the maximum weight

Enter the desired weight: 100

Enter the desired tolerance: 15

weight_min = 85

weight_max = 115