HOW DO I DO THAT IN MATLAB SERIES?

In this series, I am answering questions that students have asked me about MATLAB. Most of the questions relate to a mathematical procedure.

Contents

TOPIC

How do I use the concepts of regression,integration and nonlinear equations to solve an engineering problem

SUMMARY

Language : Matlab 2010a; Authors : Autar Kaw and Sri Harsha Garapati; Mfile available at Last Revised : January 30, 2012; Abstract: This program shows you how to apply the concepts of regression, integration and nonlinear equations in solving an practical engineering problem

clc
clear all

INTRODUCTION

disp('ABSTRACT')
disp('   This program shows you how to apply mathematical concepts of')
disp('   regression, integration and solving nonlinear equations')
disp('   to solve practical engineering problems')

disp(' ')
disp('AUTHOR')
disp('   Autar Kaw and Sri Harsha Garapati of http://autarkaw.wordpress.com')
disp(' ')
disp('MFILE SOURCE')
disp('   http://numericalmethods.eng.usf.edu/blog/shrinkfit_blog.m')
disp(' ')
disp('LAST REVISED')
disp('   January 30, 2012')
disp(' ')
ABSTRACT
   This program shows you how to apply mathematical concepts of
   regression, integration and solving nonlinear equations
   to solve practical engineering problems
 
AUTHOR
   Autar Kaw and Sri Harsha Garapati of http://autarkaw.wordpress.com
 
MFILE SOURCE
   http://numericalmethods.eng.usf.edu/blog/shrinkfit_blog.m
 
LAST REVISED
   January 30, 2012
 

PROBLEM HANDOUT

Link to Problem Description: PDF

INPUTS

% Outer diameter of the trunnion in inches
Dia=12.363;
% Coefficient of thermal expansion
alpha_room=6.47E-6;
% Temperature of the cooling fluid (Dry-Ice alcohol mixture)
Tfluid=-108;
% Room temperature
Troom=80;
% Temperature Array
temp=[80 0 -80 -100 -160  -180  -260  -280  -300 -340];
% coefficient of thermal expansion array
alpha=[6.47 6.0 5.43 5.28 4.72 4.52 3.58 3.33 3.07  2.45]*1E-6;
% Contraction needed
con_needed=0.015;

DISPLAYING INPUTS

disp('  ')
disp('INPUTS')

% printing the outer diameter of the trunnion
fprintf('  Outer diameter of the trunnion = %g\n',Dia)
% printing the coefficient of thermal expansion of steel at room temperature
fprintf('The coefficent of thermal expansion at room temperature =%g\n',alpha_room)
% printing the coefficient of cooling fluid temperature
fprintf('Temperature of cooling medium =%g\n',Tfluid)
% printing the room temperature
fprintf('Temperature of the ambient air =%g\n',Troom)
% printing the alpha as a function of temperature(Table)
format short g
disp(' ')
disp('       Alpha          Temp')
disp('       -----          ----')
data=[alpha; temp]';
disp(data)
% printing the target contraaction needed
fprintf('Contraction needed =%g"\n',con_needed)
  
INPUTS
  Outer diameter of the trunnion = 12.363
The coefficent of thermal expansion at room temperature =6.47e-006
Temperature of cooling medium =-108
Temperature of the ambient air =80
 
       Alpha          Temp
       -----          ----
    6.47e-006           80
       6e-006            0
    5.43e-006          -80
    5.28e-006         -100
    4.72e-006         -160
    4.52e-006         -180
    3.58e-006         -260
    3.33e-006         -280
    3.07e-006         -300
    2.45e-006         -340

Contraction needed =0.015"

THE CODE

% 1) Contraction of the trunnion outer diamter
deltat=Tfluid-Troom;
deltaD=Dia*alpha_room*deltat;

% 2) Regressing the the data alpha vs temperature as a second order
% polynomial (Eqn 3 from the the problem statement handout
coeff=polyfit(temp,alpha,2);
syms T
alphapoly=coeff(1)*T^2+coeff(2)*T+coeff(3);
alphapoly=vpa(alphapoly,6);

% 3) Find the contraction (Hint: Use Eqn 2 in the problem handout
deltaD3=Dia*int(alphapoly,T,Troom,Tfluid);
deltaD3=double(deltaD3);

% 4) If the contraction needed is -0.015, Find the minimum temperature that
% would be needed
syms Tf
rhs1=Dia*int(alphapoly,T,Troom,Tf);
lhs1=-con_needed;
eqn1=[char(rhs1) '=' num2str(lhs1)];
soln=solve(eqn1,Tf);
soln=double(soln);

DISPLAYING OUTPUTS

disp('  ')
disp('OUTPUTS')
% Printing the change in outer diamter of trunnion
fprintf ('\nChange in diameter prob1 i.e. taking alpha to be constant=%g in',deltaD)
% Printing the regression curve alpha vs temp
fprintf('\nPolynomial approx of alpha is %s',char(alphapoly))
% printing the actual change in dia (Taking alpha as a function of temp)
fprintf ('\nChange in diameter prob3=%g in',deltaD3)
% printing the temperature required to acheive the target contraction
fprintf ('\nFluid temp needed=%g F\n',soln(2))
  
OUTPUTS

Change in diameter prob1 i.e. taking alpha to be constant=-0.0150379 in
Polynomial approx of alpha is - 0.0000000000123011*T^2 + 0.00000000623854*T + 0.00000602754
Change in diameter prob3=-0.0137167 in
Fluid temp needed=-128.281 F