<< Chapter < Page | Chapter >> Page > |
Modify your script
in previous problem so that the user provides the following input:
Enter the initial force in N:
Enter the final force in N:
Enter the increment value:
Enter the area of small piston in mm^2:
Enter the area of big piston in mm^2:
Test your script with 150, 200, 10, 25 and 100 with respect to each input variable.
% This script computes the load carried by the larger piston in a hydraulic system
clc % Clear screendisp('This script computes the load carried by the larger piston in a hydraulic system')
disp(' ') % Display blank lineinitialF=input('Enter the initial force in N: ');finalF=input('Enter the final force in N: ');
increment=input('Enter the increment value: ');area1=input('Enter the area of small piston in mm^2: ');
area2=input('Enter the area of big piston in mm^2: ');F1=[initialF:increment:finalF]; % Creating a row vector with F1 valuesF2=F1*area2/area1; % Calculating F2 values
disp(' ') % Display blank linestr = [' F1 F2 '];% Displaying table headerdisp(str);
disp([F1' F2']) % Tabulating results in two columns, ' is being used to transpose row to column
The script output is as follows:
This script computes the load carried by the larger piston in a hydraulic systemEnter the initial force in N: 150
Enter the final force in N: 200Enter the increment value: 10
Enter the area of small piston in mm^2: 25Enter the area of big piston in mm^2: 100F1 F2
150 600160 640
170 680180 720
190 760200 800
Write a script to solve the Stress-Strain problem in the Problem Set
The m-file contains the following:
% This script uses readings from a Tensile test and
% Computes Strain and Stress valuesclc % Clear screen
disp('This script uses readings from a Tensile test and')disp('Computes Strain and Stress values')
disp(' ') % Display a blank lineSpecimen_dia=12.7; % Specimen diameter in mm
% Load in kNLoad_kN=[0;4.89;9.779;14.67;19.56;24.45;...
27.62;29.39;32.68;33.95;34.58;35.22;...35.72;40.54;48.39;59.03;65.87;69.42;...
69.67;68.15;60.81];
% Gage length in mmLength_mm=[50.8;50.8102;50.8203;50.8305;...
50.8406;50.8508;50.8610;50.8711;...50.9016;50.9270;50.9524;50.9778;...
51.0032;51.816;53.340;55.880;58.420;...60.96;61.468;63.5;66.04];% Calculate x-sectional area im m2
Cross_sectional_Area=pi/4*((Specimen_dia/1000)^2);% Calculate change in length, initial lenght is 50.8 mm
Delta_L=Length_mm-50.8;% Calculate Stress in MPa
Sigma=(Load_kN./Cross_sectional_Area)*10^(-3);% Calculate Strain in mm/mm
Epsilon=Delta_L./50.8;str = ['Specimen diameter is ', num2str(Specimen_dia), ' mm.'];disp(str);
Results=[Load_kN Length_mm Delta_L Sigma Epsilon];
% Tabulated resultsdisp(' Load Length Delta L Stress Strain')
disp(Results)
After executed, the command window output is:
This script uses readings from a Tensile test and
Computes Strain and Stress valuesSpecimen diameter is 12.7 mm.Load Length Delta L Stress Strain
0 50.8000 0 0 04.8900 50.8102 0.0102 38.6022 0.0002
9.7790 50.8203 0.0203 77.1964 0.000414.6700 50.8305 0.0305 115.8065 0.0006
19.5600 50.8406 0.0406 154.4086 0.000824.4500 50.8508 0.0508 193.0108 0.0010
27.6200 50.8610 0.0610 218.0351 0.001229.3900 50.8711 0.0711 232.0076 0.0014
32.6800 50.9016 0.1016 257.9792 0.002033.9500 50.9270 0.1270 268.0047 0.0025
34.5800 50.9524 0.1524 272.9780 0.003035.2200 50.9778 0.1778 278.0302 0.0035
35.7200 51.0032 0.2032 281.9773 0.004040.5400 51.8160 1.0160 320.0269 0.0200
48.3900 53.3400 2.5400 381.9955 0.050059.0300 55.8800 5.0800 465.9888 0.1000
65.8700 58.4200 7.6200 519.9844 0.150069.4200 60.9600 10.1600 548.0085 0.2000
69.6700 61.4680 10.6680 549.9820 0.210068.1500 63.5000 12.7000 537.9830 0.2500
60.8100 66.0400 15.2400 480.0403 0.3000
Modify the script, you wrote above and plot an annotated Stress-Strain graph.
Edited script contains the plot commands:
% This script uses readings from a Tensile test and
% Computes Strain and Stress valuesclc % Clear screen
disp('This script uses readings from a Tensile test and')disp('Computes Strain and Stress values')
disp(' ') % Display a blank lineSpecimen_dia=12.7; % Specimen diameter in mm
% Load in kNLoad_kN=[0;4.89;9.779;14.67;19.56;24.45;...
27.62;29.39;32.68;33.95;34.58;35.22;...35.72;40.54;48.39;59.03;65.87;69.42;...
69.67;68.15;60.81];
% Gage length in mmLength_mm=[50.8;50.8102;50.8203;50.8305;...
50.8406;50.8508;50.8610;50.8711;...50.9016;50.9270;50.9524;50.9778;...
51.0032;51.816;53.340;55.880;58.420;...60.96;61.468;63.5;66.04];% Calculate x-sectional area im m2
Cross_sectional_Area=pi/4*((Specimen_dia/1000)^2);% Calculate change in length, initial lenght is 50.8 mm
Delta_L=Length_mm-50.8;% Calculate Stress in MPa
Sigma=(Load_kN./Cross_sectional_Area)*10^(-3);% Calculate Strain in mm/mm
Epsilon=Delta_L./50.8;str = ['Specimen diameter is ', num2str(Specimen_dia), ' mm.'];disp(str);
Results=[Load_kN Length_mm Delta_L Sigma Epsilon];
% Tabulated resultsdisp(' Load Length Delta L Stress Strain')
disp(Results)% Plot Stress versus Strain
plot(Epsilon,Sigma)title('Stress versus Strain Curve')
xlabel('Strain [mm/mm]')
ylabel('Stress [mPa]')
grid
In addition to Command Window output, the following plot is generated:
Repeat
Problem 2 , this time using a combination of
disp
,
fprintf
commands and a
for
loop.
The re-worked solution:
% This script generates a table of conversions
% From Fahrenheit to Celsius temperaturesclear % removes all variables from the current workspace,
clc % clears all input and output from the Command Window display,disp('This script generates a table of conversions from Fahrenheit to Celsius')
disp(' ') % Display blank linelowerF=input('Enter the initial temperature in F: ');
upperF=input('Enter the final temperature in F: ');increment=input('Enter the increment value: ');
disp(' ') % Display blank linefprintf('Fahrenheit Celsius\n') % title row
fprintf('------------------\n') % title rowfor Fahrenheit=[lowerF:increment:upperF]; % Creating a row vector with F valuesCelsius=5/9*(Fahrenheit-32); % Converting from F to C
fprintf('%8.3f %8.3f \n',Fahrenheit,Celsius); % Tabulating results in two columnsend
After executed, the command window output is:
This script generates a table of conversions from Fahrenheit to CelsiusEnter the initial temperature in F: 20
Enter the final temperature in F: 200Enter the increment value: 20Fahrenheit Celsius
------------------20.000 -6.667
40.000 4.44460.000 15.556
80.000 26.667100.000 37.778
120.000 48.889140.000 60.000
160.000 71.111180.000 82.222
200.000 93.333
Repeat
Problem 7 , this time using a
while
loop.
The re-worked solution:
% This script generates a table of conversions
% From Fahrenheit to Celsius temperaturesclear % removes all variables from the current workspace,
clc % clears all input and output from the Command Window display,disp('This script generates a table of conversions from Fahrenheit to Celsius')
disp(' ') % Display blank linelowerF=input('Enter the initial temperature in F: ');
upperF=input('Enter the final temperature in F: ');increment=input('Enter the increment value: ');
disp(' ') % Display blank linefprintf('Fahrenheit Celsius\n') % title row
fprintf('------------------\n') % title rowFahrenheit=lowerF;
while Fahrenheit<=upperF
Celsius=5/9*(Fahrenheit-32); % Converting from F to Cfprintf('%8.3f %8.3f \n',Fahrenheit,Celsius); % Tabulating results in two columns
Fahrenheit=Fahrenheit+increment;end
After executed, the command window output is:
This script generates a table of conversions from Fahrenheit to CelsiusEnter the initial temperature in F: 20
Enter the final temperature in F: 200Enter the increment value: 20Fahrenheit Celsius
------------------20.000 -6.667
40.000 4.44460.000 15.556
80.000 26.667100.000 37.778
120.000 48.889140.000 60.000
160.000 71.111180.000 82.222
200.000 93.333
Notification Switch
Would you like to follow the 'A brief introduction to engineering computation with matlab' conversation and receive update notifications?