## Matlab Assignment Solution on Torsion Analysis

- 12th Aug, 2022
- 15:18 PM

function Torsion_Analysis()

clear all;

clc;

data=[0.30 1.18

0.26 1.23

0.22 1.15

0.18 1.21

0.14 1.32

0.10 1.48

0.06 1.63

0.02 2.07];

ratio =data(:,1); % dimension (r/d) values

k=data(:,2); % concentration factor values

%%

% Problem 1(a)

%

% k=b*(r/d)^m; or log(k)=mlog(r/d) +log(b)

% [y=mx+c]: equation of a line whose slope is m and y-intercept is c

figure(1)

x=log(ratio); y=log(k);

n=1; ?gree of polynomial

p=polyfit(x,y,n);

x1=linspace(min(x),max(x)); y1=polyval(p,x1);

plot(x,y,'o')

hold on

plot(x1,y1,'b','LineWidth', 1.5)

xlabel 'log(r/d)', ylabel 'log(k)';

title('Question 1(a): [Your Name/CSU ID]')

hold off

c=0.75; % y-intercept. Read from the graph

b= exp(c); % since c=log(b)

%

% The line passes through the last point and second last point

m=(y(end)-y(end-1))/(x(end)-x(end-1)); % gradient or slope

fprintf('>> m=%.4f,\t b=%.2f\n',m,b)

%

% Create Table

log_k_predicted= [0.12,0.15,0.18,0.25,0.30,0.38,0.4886,0.7275]; % read from graph

% log_k_predicted=m*x1+log(b);

k_predicted=exp(log_k_predicted)';

varNames={'Experimental_k_data','Predicted_k_values'};

Table=table(k,k_predicted,'VariableNames',varNames);

Tableu=Table(:,:) % Display table with all data

%%

% Problem 1(b)

%

figure(2)

n=4; ?gree of polynomial

p1=polyfit(ratio,k,n);

x2=linspace(min(ratio),max(ratio)); y2=polyval(p1,x2);

plot(ratio,k,'o')

hold on

plot(x2,y2,'b','LineWidth', 1.5)

xlabel 'Dimensions, (r/d)', ylabel 'Concentration factor, k';

title('Question 1(b): [Your Name/CSU ID]')

hold off

%%

% Problem 1(c)

%

% Create Table

dim=[0.05, 0.10, 0.15, 0.20, 0.25, 0.30]'; % r/d values

k_a=b*(dim.^(m));

k_l=m*dim+c;

varNames={'r_d_ratios','Equation_in_a','Linear_interpolation'};

Table1=table(dim,k_a,k_l,'VariableNames',varNames);

Tableu1=Table1(:,:) % Display table with all data

end