lab11 everything

docx

School

University of North Texas *

*We aren’t endorsed by this school

Course

311K

Subject

Computer Science

Date

Feb 20, 2024

Type

docx

Pages

6

Uploaded by ChiefBear2683

Report
Lab 11 Harish Sridharan CE 311K Lab 11 Fortran Code ! CE311K Introduction to Computer Methods ! Lab11 - Integration Program lab11 implicit none Real Length, alpha Real upper, lower Real F_Tr,F_S13,F_S38,Int_Tr,Int_S13,Int_S38 Real d_Tr,d_S13,d_S38, T_Tr, T_S13, T_S38 Integer i, num, seg(18) ! Open Output File Open (unit=6, file= 'lab11out.dat' , status= 'unknown' ) !input data, define Lenght as 10, alpha as 40 degrees Length=10. alpha=40. alpha=alpha*(3.1415926/180) !conversion of degrees to radians write (6,*) alpha 100 Format (2/, 23x, f4.1, /, 29x, f4.0) Data seg /1,2,3,4,5,7,10,12,15,20,30,50,100,200,300,400,500,1000/ ! Initialization of upper and lower bounds lower = 0.0 upper = Length - lower ! Writing Headers Write (6,200) Write (6,210) Write (6,200) Do i=1,18 ! Calculation of Force and centroid num= seg(i) Call Trapezoidal(lower, upper, num, F_Tr, Int_Tr) Call Simpson13(lower, upper, num, F_S13, Int_S13) Call Simpson38(lower, upper, num, F_S38, Int_S38) d_S38 = Int_S38/F_S38 d_S13 = Int_S13/F_S13 d_Tr = Int_Tr/F_Tr ! Calculation of Tension T_S38 = d_S38*F_S38/(Length* sin (alpha))
T_S13 = d_S13*F_S13/(Length* sin (alpha)) T_Tr = d_Tr*F_Tr/(Length* sin (alpha)) ! Write results into the output file Write (6, 250) seg(i), F_Tr, T_Tr, F_S13, T_S13, F_S38, T_S38 Enddo 200 Format (80( '=' )) 210 Format ( 'Calculated Load and the Tension of the Cable' ,2/,& '# of Segments' ,10x, 'Trapezoidal' ,10x, 'Simpson13' ,12x,& 'Simpson38' ,/,20x,3( 'Force Tension ' )) 250 Format (2x,i4,11x,f9.4,1x,f9.4,2x,f9.4,1x,f9.4,2x,f9.4,1x,f9.4) End !---------------------------------------------------- !lower is lower limit, upper is upper limit ! num is the number of intervals that will be used for the integral ! Int 1 contains the integral of f(x) between lower and upper with num intervals ! Int 2 contains the integral of xf(x) between lower and upper with num intervals Subroutine Simpson38(lower, upper, num, Int1, Int2) implicit none Real lower, upper, Int1, Int2, x, x0, x1, x2, x3, h Real q, xq Integer i, num ! Define functions q(x) = 100*x/(1+x)* exp (-0.5*x) xq(x)= 100*x**2/(1+x)* exp (-0.5*x) ! Initialization ! Define de value of the step h h=(upper-lower)/(3*num) !initialize the values of the integral at zero Int1=0 Int2=0 ! Calculation of Integrals Do i=1, num x0 = lower+3*h*(i-1) x1 = x0 +h x2 = x1 +h x3 = x2 +h Int1= Int1+(3.*h/8)*(q(x0)+3.*q(x1)+3.*q(x2)+q(x3)) Int2= Int2+(3.*h/8)*(xq(x0)+3.*xq(x1)+3.*xq(x2)+xq(x3)) Enddo Return End !------------------------------------------------------ Subroutine Simpson13(lower, upper, num, Int1, Int2) implicit none Real lower, upper, Int1, Int2, x, x0, x1, x2, h Real q, xq Integer i, num ! Define functions q(x) = 100*x/(1+x)* exp (-0.5*x) xq(x)= 100*x**2/(1+x)* exp (-0.5*x) ! Initialization h=(upper-lower)/(2*num) Int1=0 Int2=0
! Calculation of Integrals Do i=1, num x0 = lower+2*h*(i-1) x1 = x0+h x2 = x1+h Int1= Int1+(h/3.)*(q(x0)+4.*q(x1)+q(x2)) Int2= Int2+(h/3.)*(xq(x0)+4.*xq(x1)+xq(x2)) Enddo Return End !------------------------------------------------------ Subroutine Trapezoidal(lower, upper, num, Int1, Int2) implicit none Real lower, upper, Int1, Int2, x, x0, x1, h Real q, xq Integer i, num ! Define functions q(x) = 100*x/(1+x)* exp (-0.5*x) xq(x)= 100*x**2/(1+x)* exp (-0.5*x) ! Initialization h=(upper-lower)/num Int1=0 Int2=0 ! Calculation of Integrals Do i=1, num x0 = lower+h*(i-1) x1 = x0+h Int1= Int1+(h/2.)*(q(x0)+q(x1)) Int2= Int2+(h/2.)*(xq(x0)+xq(x1)) Enddo Return End
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Lab 11 MATLAB Code %% Lab 11 Integration % % Author: Hagen Fritz % Date: 09/04/2018 % Department: UT CAEE %% Declaring Symbolic Variables % Declare the symbolic variables q F T d x and M. Remember, you can do this % on a single line but do NOT put commas in between the variable names. If % you did it right, each variable should be highlighted. syms q F T D x M % Create a variable L and set it equal to 10 L=10; % Create a variable ang that will be equal to the angle in degrees (40) ang = 40; % Create the symbolic expressions for q and qx. qx will be almost identical % to q except that it will be multiplied by x. The powerpoint has the % formula for q that you will need. Simply copy this down with the proper % syntax. q = 100*(x/(1+x))*exp(1)^(-0.5*x); qx = x*q; %% Calculation of Variables % Calculate the force using the int() function. You will have four inputs: % the function (q), the variable you are integrating with respect to (x), % the lower bound (0), and the upper bound (L). F = int(q,x, 0,10); % Right now F is still a symbolic expression even though the expression can % be solved to a single solution. Convert F to a double variable by saying % F = double(F); F= double(F); % Calculate the moment using the int() function. In this case, your inputs % will be similar to when you calculated the force except now your function % will be qx. M= int(qx,x, 0,10); % Again convert the symoblic moment equation to a double using double(). M= double(M)
% The centroid is given as the moment divided by the force. You have these % two values so solve for the centroid, d. d= M/F % The equation for tension is given on the powerpoint. Remember to use the % correct function to calculate the sine of the angle. Matlab has two: one % that calculates sine using degrees and another using radians. T= d*F/(L*sind(40)) %% Printing out Variables % Force % Print out the value of the force using fprintf. Remember you need the % format specifier in single quotes. Also be sure to report the UNITS of % force and then end your literal text (portion in the single quotes) with % a \n. This will bring you to the next line. fprintf( 'The Force is equal to: %.2f N \n' , F) % Centroid % Print out the value of the centroid using fprintf and be sure to report % your units. Again, place a \n at the end of your text so you move to the % next line. fprintf( 'The Centroid is equal to: %.2f m \n' , d) % Tension % Print out the value of the Tension using fprintf and be sure to report % your units. fprintf( 'The Tension is equal to: %.2f N \n' , T) %% Assignment % 1. Declare your symbolic variables on line 13 % 2. Create two variables L and ang on lines 17 and 21 respectively % 3. Write out the expressions for q and qx on lines28 and 29, respectively % 4. Use the int() function on q and qx to get the force and moment on % lines 37 and 49 % 5. Use double() to change the force and moment variables from symbolic % variables to double precision (called "casting"); % 6. Calculate the centroid and tension force on lines 58 and 64 % 7. Output the centroid and tension values on lines 80 and 86 %% What to turn in % 1. Copy and paste this matlab code into your master Word Document % 2. Copy and paste your output on the Command Window to your master Word % Document. You should have the force, tension, and centroid. % 3. Submit your Matlab source code (.m file) separately
Lab 11 MATLAB Output
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help