Im stuck on my MATLAB project Using the information given wr
I\'m stuck on my MATLAB project. Using the information given, write a code in MATLAB that shows that you: calculated the moment of inertia, calculate the maximum stress and deflection, calculate the costs, calculate the deflection and max deflection, plot the deflection curves, and, using fprintf, display the cost of each beam, and the max deflection of each beam. The images below give more detail. I am to analyse a cylindrical beam.
Solution
P=100; % Load in N
 E=2*10^11; % E in N/m^2
 L=10; %assumed length in m
 A=linspace(0,L,501);
Dia=[0.175 0.15 0.15 0.175];
 Thi=[0.01 0.03 0.05 0.02];
 LinearCost=[134 164 186 225];
 m=size(Dia,2);
 n=size(A,2);
 for i=1:m
     D=Dia(i);
     t=Thi(i);
     I=pi/64*(D^4-(D-2*t)^4);
     c=D;
     for j=1:n
         a=A(j);
         b=L-a;
         Maxs(j)=P*a*(L-a)*c/(I*L);%max stress for various location of load
         for k=1:n
             x=A(k);
             if x<A(j)
                 def(k)=abs(P*b*x/(6*E*I*L)*(L^2-x^2-b^2));
             else
                 def(k)=abs(P*b/(6*E*I*L)*(L/b*(x-a)^2+(L^2-b^2)*x-x^3));
             end        
         end
         MaxDef(j)=max(def);%max deflection for various location of load
     end
     maximumStress=max(Maxs); %maximum stress for the given beam
     maximumDef=max(MaxDef); %maximum deflection for the given beam
     cost=LinearCost(i)*L;
     fprintf(\' maximum stress is: %f \ \', maximumStress);
     fprintf(\' maximum deflection is: %f\ \', maximumDef);
     fprintf(\' cost of beam: %f \ \', cost);
     fprintf(\'next beam\ \')
 end
%output%
maximum stress is: 2471007.461573
 maximum deflection is: 0.004236
 cost of beam: 1340.000000
 next beam
 maximum stress is: 1733713.977036
 maximum deflection is: 0.003467
 cost of beam: 1640.000000
 next beam
 maximum stress is: 1527887.453682
 maximum deflection is: 0.003056
 cost of beam: 1860.000000
 next beam
 maximum stress is: 1471370.028914
 maximum deflection is: 0.002522
 cost of beam: 2250.000000


