richyo1000
richyo1000

Reputation: 190

vary cylinder wall thickness to find matching stiffness of other materials?

morning So'ers! So i'm stuck again... I'm trying to determine an optimum wall thickness for a cylinder using different materials. I have a current tube (Iron) and i know the stiffness ('k') for this. I'm trying to use matlab to iterate through different 'd' (internal dia.) values and stop when the stiffness value, k, is the same (or similar) to the k i have for the iron tube (if it does indeed converge!) I've tried while and for loops but something is not right! any advice is appreciated, cheers

clc
Efe = 211e9;     % Youngs modulus for iron [GPa]
Eal = 69e9;      % Youngs modulus for Aluminium [GPa]
Esteel = 200e9;  % Youngs modulus for steel [GPa]

D = 53           % Outer diameter [mm]
dFe = 36         % Inner diameter [mm]
dguess = 36
disp('Second moment of area for Iron cylinder: ')
IFe = pi*(D.^4-dFe.^4)/64
    I = pi*(D.^4-dguess.^4)/64
disp('Stiffness for Iron: ')
Stiffness_Fe = Efe/IFe
disp('Stiffness for Aluminium: ')
Stiffness_Al = Eal/I

d=D;
while Stiffness_Fe>Stiffness_Al
    d=d-1
    I = pi*(D.^4-d.^4)/64;
    Stiffness_Al=Stiffness_Fe
        if d<0;
            disp('Gone negative, step out')
        break;
    end
end

d

i was hopeful that the for loop version would work but it seems i cannot use the Stiffness_Al variable in this loop correctly....I could probably get this done on a spreadsheet and filter for matching values of 'k' but it's normally more fun to use matlab (except when i struggle with basic stuff such as this!)

Upvotes: 0

Views: 448

Answers (1)

High Performance Mark
High Performance Mark

Reputation: 78364

The logic of your loop is wonky;

while Stiffness_Fe>Stiffness_Al
    d=d-1
    I = pi*(D.^4-d.^4)/64;
    Stiffness_Al=Stiffness_Fe
        if d<0;
            disp('Gone negative, step out')
        break;
    end
end

The loop will, as written, continue until Stiffness_Fe exceeds Stiffness_Al. This statement is true when your code first encounters the loop. Three statements along you set Stiffness_Al equal to Stiffness_Fe. Nowhere else in your loop is either of these values modified, so at the end of the first iteration, when the expression Stiffness_Fe>Stiffness_Al is again evaluated it will be false and control will pass to the statements after the loop.

It is very odd indeed to write a while loop in such a way that (a) it always runs once and (b) it never runs twice. In terms of loops, it's not much of a loop.

I surmise that what you are trying to do is to calculate the stiffness of a range of aluminium tubes of varying inside diameter, and to find the one with the smallest inside diameter with the same stiffness as your iron tube. I think that I would:

  1. Create a vector of inside diameters, from some minimum value up to 1mm less than the outside diameter, for example inside_diameters = 12:52.
  2. Calculate the stiffness of tube for each element of that vector, something like stiffnesses = Eal/(pi*(D.^4-inside_diameters.^4)/64)
  3. Find the smallest value in stiffnesses which exceeds the stiffness of the iron tube.

If you want to cover a wider array of tube thicknesses you could try 12:0.1:52. Unless you want or need a much more precise figure Matlab will generate the figures you want in the time it takes you to hit the return key.

Yes, it might be more elegant to increase the thickness step-by-step and break from the loop when you find the value you're looking for, but I'd suggest you worry about getting your code working then, if you have the time and the inclination, polish it up.

Upvotes: 3

Related Questions