Week 9 - Programming III Today: – Another loop option – A programming example: tic-tac-toe Textbook chapter 7, pages 213-216, 219-226 (sections 7.4.2,

Slides:



Advertisements
Similar presentations
MATLAB Examples. CS 1112 MATLAB Examples Find the number of positive numbers in a vector x = input( 'Enter a vector: ' ); count = 0; for ii = 1:length(x),
Advertisements

Fick’s Laws Combining the continuity equation with the first law, we obtain Fick’s second law:
Week 10 - Project Today: – Team formation: 3 or 4 students each – Schedule: Progress meetings – during April Oral presentation/demo – final exam day Written.
FIRST AND SECOND-ORDER TRANSIENT CIRCUITS
Flow Charts, Loop Structures
Current. Current Current is defined as the flow of positive charge. Current is defined as the flow of positive charge. I = Q/t I = Q/t I: current in Amperes.
Solid State Diffusion-1
James Tam Loops In Python In this section of notes you will learn how to rerun parts of your program without having to duplicate the code.
Example – calculating interest until the amount doubles using a for loop: will calculate up to 1000 years, if necessary if condition decides when to terminate.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 5 Looping.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 5: Looping by Tony.
Precedence Parentheses Arithemetic ^ * / + - (exception logical not ~ ) Relational > =
Loops – While, Do, For Repetition Statements Introduction to Arrays
Week 7 - Programming I Relational Operators A > B Logical Operators A | B For Loops for n = 1:10 –commands end.
CHAPTER 5 Diffusion 5-1.
Loops For loop for n = [ ] code end While loop while a ~= 3 code end.
Precedence Parentheses Arithemetic ^ * / + - (exception logical not ~ ) Relational > =
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 6: Repetition  Some additional operators increment and decrement.
Thermally Activated Processes and Diffusion in Solids
EGR 106 – Project Intro / While Loop Project description Project schedule Background information / terminology A simple example Examples of similar programs.
Week 7 - Programming II Today – more features: – Loop control – Extending if/else – Nesting of loops Debugging tools Textbook chapter 7, pages
Linear Equations and Functions
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
CHE 333 Class 11 Mechanical Behavior of Materials.
Introduction Material transport by atomic motion Diffusion couple:
Chapter 4: Loops and Files. The Increment and Decrement Operators  There are numerous times where a variable must simply be incremented or decremented.
ENGR-25_Programming-3.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.
V. Diffusion in Solids MECE 3345 Materials Science 1 VI. Diffusion in Solids copyright © 2008 by Li Sun.
© 2006 Pearson Education 1 More Operators  To round out our knowledge of Java operators, let's examine a few more  In particular, we will examine the.
EGR 106 – Functions Functions – Concept – Examples and applications Textbook chapter p15-165, 6.11(p 178)
CTC / MTC 322 Strength of Materials
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 5 Looping.
+ Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 5: Looping.
CHE 333 CLASS 20 DIFFUSION.
>> x = [ ]; y = 2*x y = Arrays x and y are one dimensional arrays called vectors. In MATLAB all variables are arrays. They allow functions.
1 Standard Version of Starting Out with C++, 4th Brief Edition Chapter 5 Looping.
ENGR-45_Lec-07_Diffusion_Fick-2.ppt 1 Bruce Mayer, PE Engineering-45: Materials of Engineering Bruce Mayer, PE Registered Electrical.
© The McGraw-Hill Companies, 2006 Chapter 3 Iteration.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 3 Friday 03 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Chapter 1 Diffusion in Solids. Diffusion - Introduction A phenomenon of material transport by atomic migration The mass transfer in macroscopic level.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 5 Looping.
Week 10- Project week 1 - Diffusion Today: – Project forms – Assignment – Examples – Second Test.
Diffusion Chapter 5. Mechanics of Diffusion Primary method by which atoms mix Consider a drop of food coloring in a glass of water.
Research Paper. Chapter 7: DOPANT DIFFUSION DOPANT DIFFUSION Introduction Introduction Basic Concepts Basic Concepts –Dopant solid solubility –Macroscopic.
Introduction to Loop. Introduction to Loops: The while Loop Loop: part of program that may execute > 1 time (i.e., it repeats) while loop format: while.
© 2006 Pearson Education Chapter 3 Part 2 More about Strings and Conditional Statements Loops (for and while) 1.
CHAPTER 5: DIFFUSION IN SOLIDS
Diffusion Thermally activated process
Current Electricity and Elastic Properties
NON-STEADY STATE DIFFUSION
Chapter 5: Looping Starting Out with C++ Early Objects Seventh Edition
Point Defects in Crystalline Solids
Linear Equations and Functions
FIRST AND SECOND-ORDER TRANSIENT CIRCUITS
Week 8 - Programming II Today – more features: Loop control
Chapter 5: Diffusion in Solids
Chapter 5: Looping Starting Out with C++ Early Objects Seventh Edition
Outline Altering flow of control Boolean expressions
Chapter 7: DOPANT DIFFUSION
Rate Process and Diffusion
3.5- The while Statement The while statement has the following syntax:
Loop Statements & Vectorizing Code
Topics Introduction to Repetition Structures
Loop Statements & Vectorizing Code
PDT 153 Materials Structure And Properties
Mechanical Properties Of Metals - I
Diffusion Chapter 5 9/4/2019 9:52 AM9/4/2019 9:52 AM
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Presentation transcript:

Week 9 - Programming III Today: – Another loop option – A programming example: tic-tac-toe Textbook chapter 7, pages , (sections 7.4.2, 7.7)

Quiz on Thursday – meet in 112 Kirk.

Longer Running Loops for loops repeat a fixed number of times: for variable = {array of length n} {commands} end and break can be used to stop earlier. Question: How about repeating “until done”? Run as long as is needed.

Answer: M ATLAB ’s “while” loop: while expression {commands to be repeated as long as expression is true} end

Prior example – compounded interest until the amount doubles: value = 1000; for year = 1:1000 value = value * 1.08; disp([num2str(year),' years: $ ',num2str(value) ]) if value > 2000 break end for loop terminated with break

Expected output:

while version format bank value = 1000; while value < 2000 value = value * 1.08; disp(value) end

Example – Collecting and storing data until a zero is entered: x = [ ]; new = 1; while new ~= 0 new = input('enter value '); x = [ x, new ]; end x = x(1:end–1) empty array to drop the zero initialize

Example – Getting valid keyboard input: E.g. forcing the user’s input to be between 0 and 10: x = –3; while ( x 10 ) x = input( 'type a value ' ); end

or: x = input('enter value '); while (x 10) disp('invalid choice'); x = input('enter value '); end disp('finally!');

Example – computing pi:

Example – “infinite” Hi-Lo: numb = round (10*rand(1)); done = 0; while ~done guess = input('guess'); if guess = = numb disp( 'You got it !!!' ); done = 1; elseif guess > numb disp('too high') else disp('too low') end initialization single guess loop control

Nesting of while loops while expression1 {outer loop commands} while expression2 {inner loop commands} end {more outer loop commands} end these can also be more than 2 levels deep

Example of Programming: tic-tac-toe Play tic-tac-toe, human against human: – Track moves – Show board – Recognize end of game

3-by-3 array for the board: – Empty cell = 0 – X = +1 – O = – 1 Game end: – Winner if row, col, or diag sum = +3 or –3 – Draw is no zeros left Loop for game: – Initial move (X) plus 4 pairs of moves – Break if winner

1. Initialization, including graphics 2. Get X’s first move 3. Loop 4 times: – Get O’s move, check for win – Get X’s move, check for win – Break on victory 4. Check for draw Program flow:

Flowchart:

Program Outline:

Program Details: Initialization

Board Graphic

Get and Show First Move (X)

Start Loop with the Second Player

Check for Victory by O

Finish Loop with the First Player

Check for a Draw

Typical Output

Semester Project Intro CARBURIZING GEARS – Diffusion of atomic carbon into steel allows very hard iron carbides to form near surface. These “cases” are hard and very wear resistant so are used to make gears. – Project is to model this for a variety of different conditions.

Example of Diffusion Leading to Failure Steel plate with a hydrogen blister in it. H+H  H 2 Atomic hydrogen from surface moves through steel until it combines to form molecular hydrogen which cannot move in steel. Pressure builds forming blister

Stress Strain Curves The load extension data can be transformed into Stress Strain data by normalizing with respect to material dimensions. The stress is the load divided by the original cross sectional area.  = L/A s – stress, units MPa, or psi or ksi L – load applied A – original cross sectional area The strain is the increase in normalized by the original length. e =  l/l e – strain – dimensionless (in/in)  l – increase in length l – original length Strain is often given in percent so x100 As the normalizations are by constants the shapes of the curves stays the same Builds on mechanical behavior from EGR 105 which was elastic deformation Stress Strain Failure Point EGR 105 Range

De-Carburization Decarburization at 1200F after quench crack in material. The crack left enough open surface for the carbon to diffuse out and leave a ferrite layer either side of the crack.

Diffusion – Basics. Atomic carbon is diffusing through steel Diffusion follows Arhenius equation so activation energy controlled D = D o exp (–Q/RT) –create as a function? D – diffusion coefficient (m 2 /s) D o - temp independent pre-exponent (m 2 /s) Q – activation energy (kJ/mol ) R – gas constant 8.31 J/mol-k T – absolute temp (K) Temperature dependent.

DIFFUSION- Units R J/mol-K; cal/mol-K; 8.62 ev/atom-K Q – J/mol; cal/mol; ev/atom. (1ev/atom = 23kcal/mol)

Non Steady State Ficks 2 nd Law Non Steady State – Concentration changes at position x as a function of time, eg Cu Ni  c/  t=D(  2 C/  x 2 ) Ficks 2 nd Law Solution to this :- Cx-Co/Cs-Co= 1- erf(x/ 2 ((Dt) -1/2 )) Cx – concentration at depth x at time t, wt% Co – concentration in average in bulk, wt % Cs – concentration at surface, fixed with time t, wt% Co- concentration in average in bulk, wt% Erf – error function – look up in tables. x – distance below surface, m D – diffusion coefficient, m 2 /s t – time in seconds

Diffusion Rates SoluteSolventD at 500 CDat1000 C CarbonBCC iron5x x10 -9 CarbonFCC iron5x x IronBCC iron x NickelFCC iron x Silver Silver Xtal SilverSilver Grain Bound Interested in carbon in iron. First assignment – need to be able to find D at any temperature to use in Fick’s second law. Thursday lab assignment - use Arhenius equation as a function? Look at week 5 notes for plot of D v1/T.

Example Time for the carbon concentration at 500C to reach half way between the steel composition level and the external level at 0.5mm below the surface. Using Fick’s second law Cx-Co/Cs-Co= 1- erf(x/ 2 ((Dt )-1/2 )) The left hand side is = 1- erf(x/ 2 ((Dt )-1/2 )) Rearranging 0.5 = erf(x/ 2 ((Dt )-1/2 )) 0.5 = erf(0.5205) So 0.5=(x/ 2 ((Dt )-1/2 )) Dt = x 2 t=x 2 /D =(5x10 -4 ) 2 /(5x ) t= 25x10 -8 /5x =5x10 4 sec =13.8 hours

Overall Project A program that will take input such as temperature, steel composition, and carbon concentration in the surrounding environment then as output be able to graphically show carbon concentration profiles in the steel as a function of time and treatment temperature. In between the input and output is the program in “Matlab” An oral report using Powerpoint. A two page written report per team.

Teams Vertical – have a team leader responsible for all organization of team and output. The leader assigns work to team members. Team members report only to team leader. Team leader must ensure assigned tasks are completed by team member. Allows for individual meetings.

Teams Horizontal – all members responsible for organization and output. Work assignment is a group activity. Task completion could be group as well. All meetings team meetings. Which team depends on personnel. You should decide which type of team.

STRATEGIC PLANNING? Once you decide on team type, develop a “Strategic Plan” – What are the teams objectives? How are you going to achieve them? Write it out so the team can follow it. Companies and other organizations have “Vision and Mission Statements” as well a strategic plans. Meet next Tuesday with strategy and first assignment from Thursday lab complete.