EGR 106 – Functions Functions – Concept – Examples and applications Textbook chapter 6.1-6.7p15-165, 6.11(p 178)

Slides:



Advertisements
Similar presentations
Lecture on DIFFUSION IN SOLIDS. Applications of Diffusion in Solids
Advertisements

Lecture 14 User-defined functions Function: concept, syntax, and examples © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Using MatLab and Excel to Solve Building Energy Simulation Problems Jordan Clark
Chapter 6 Diffusion in Solids.
Chapter ISSUES TO ADDRESS... How does diffusion occur? Why is it an important part of processing? How can the rate of diffusion be predicted for.
Fick’s Laws Combining the continuity equation with the first law, we obtain Fick’s second law:
CHAPTER 6: DIFFUSION IN SOLIDS
Functions MATLAB’s power comes from functions Functions allow projects to be partitioned into manageable, testable, reusable modules.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
CHAPTER 5: DIFFUSION IN SOLIDS
CHAPTER 5 Diffusion 5-1.
EGR 106 – Week 7 – Functions Function concept and an example Rules for functions Local and global variables More examples Errors Application: zeroes and.
EGR 106 – Week 8 Data Files & Functions Interacting with Data Files Functions – Concept – Examples and applications Textbook chapter ,
An Introduction to Heat Flow
EGR 106 – Week 5 – Functions Function concept and an example Rules for functions Local and global variables More examples Errors Application: zeroes and.
Thermally Activated Processes and Diffusion in Solids
Diffusion Diffusion means atoms moving and changing places. This happens in solids and liquids, exactly in the same way that an unpleasant smell moves.
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Introduction to programming in MATLAB MATLAB can be thought of as an super-powerful graphing calculator Remember the TI-83 from calculus? With many more.
Rev.S08 MAC 1105 Module 3 System of Equations and Inequalities.
Motion.
Linear Algebra Achievement Standard 1.4.
DIFFUSION IN SOLIDS  FICK’S LAWS  KIRKENDALL EFFECT  ATOMIC MECHANISMS Diffusion in Solids P.G. Shewmon McGraw-Hill, New York (1963)
Introduction To Materials Science, Chapter 5, Diffusion University of Virginia, Dept. of Materials Science and Engineering 1 Diffusion  how atoms move.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB is a powerful program for numerical computations, plotting and programming.
Introduction to MATLAB ENGR 1181 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Matlab Programming for Engineers Dr. Nidal Farhat Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
Relative Energy Levels of Defects Information was extracted from: Porter and Easterling, Phase Transformations in Metals and Alloys, 2nd Edition, CRC Press,
Introduction Material transport by atomic motion Diffusion couple:
Functions CS 103 March 3, Review A function is a set of code we can execute on command to perform a specific task A function is a set of code we.
Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Introduction to Engineering MATLAB – 2 Introduction to MATLAB - 2 Agenda Defining Variables MATLAB Windows.
Chapter 5 Review Advanced Algebra 1. System of Equations and Inequalities - System of Linear Equations in Two Variables - Solutions of Linear Inequalities.
V. Diffusion in Solids MECE 3345 Materials Science 1 VI. Diffusion in Solids copyright © 2008 by Li Sun.
COMP 116: Introduction to Scientific Programming Lecture 11: Functions.
Getting Started with MATLAB (part2) 1. Basic Data manipulation 2. Basic Data Understanding 1. The Binary System 2. The ASCII Table 3. Creating Good Variables.
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.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
Junction Formation The position of the junction for a limited source diffused impurity in a constant background is given by The position of the junction.
Week 9 - Programming III Today: – Another loop option – A programming example: tic-tac-toe Textbook chapter 7, pages , (sections 7.4.2,
ENGR-45_Lec-07_Diffusion_Fick-2.ppt 1 Bruce Mayer, PE Engineering-45: Materials of Engineering Bruce Mayer, PE Registered Electrical.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
Chapter 1 Diffusion in Solids. Diffusion - Introduction A phenomenon of material transport by atomic migration The mass transfer in macroscopic level.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
ENG College of Engineering Engineering Education Innovation Center 1 Functions 1 in MATLAB Topics Covered: 1.Uses of Functions Organizational Tool.
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.
Cycling of Matter in Living Systems 2.2 The Role of Cell Membrane in Transport.
Phase Diagrams Chapter 9 4 th Edition Chapter 10 5 th Edition.
Transferência de Energia e de Massa Energy and Mass Transfer Lecture 1: Introduction to the subject and to the course 1.
EGR 106 – Week 5 – 2-D Plots Question : Why do engineers use plots? Answer : To analyze, visualize, and present data. Matlab has many useful plotting options.
Unit 3 – Chemical Reactions.  Matter cannot be created or destroyed, but merely changed, converted or rearranged  In a chemical reaction, the total.
Try not to have a good time...this is supposed to be educational
CHAPTER 5: DIFFUSION IN SOLIDS
Diffusion Thermally activated process
Chapter 5: Diffusion ISSUES TO ADDRESS... • How does diffusion occur?
Introduction to Programming for Mechanical Engineers
Diffusion how atoms move in solids
Chapter 5: Diffusion in Solids
Matlab review Matlab is a numerical analysis system
Example Ni-base superalloy
Rate Process and Diffusion
MSIS 655 Advanced Business Applications Programming
CHAPTER 8 Phase Diagrams 1.
CHAPTER 8 Phase Diagrams 1.
CHAPTER 5: DIFFUSION IN SOLIDS
Rate Process and Diffusion
Diffusion Chapter 5 9/4/2019 9:52 AM9/4/2019 9:52 AM
Presentation transcript:

EGR 106 – Functions Functions – Concept – Examples and applications Textbook chapter p15-165, 6.11(p 178)

“Function” concept So far, you have: – used Matlab’s built-in functions – written scripts Function: – Reusable script, sometimes called a subprogram – Building block for larger programs – Often computes an output from an input

Example Function: DEG2RAD

Usage: Syntax is just like a built-in functions Application is independent of the variable names within the function (x,y) Executed by typing name (input)

Rules for Functions First line of the file must be of the form: function [outputs] = name(inputs) Identifies a function file List of function result variables List of any variables that the function needs Name of the function and the file (name.m)

inputs: – Used to transfer data into the function from the workspace Workspace variables are unavailable within the function Any necessary variables must be brought in – For multiple inputs: Separate them by commas Order is important – Examples of built-in functions with inputs: sum(x)plot(x,y)

outputs: – Used to transfer results back into the workspace from the function – For multiple outputs: Separate them by commas in brackets Order is important – Output variables must be assigned – Examples of built-in functions with outputs: y = sum(x) [value,location] = max(x)

Note – brackets on the left only make sense for functions: [value,location] = max(x) is okay [value,location] = [ 1, 2 ] is not Default output is the first one: [value,location] = max(x) value = max(x)

Global Variables To use variables in function and also workspace, use “Global variables” Command “global temperature time weight” MUST DECLARE THEM “GLOBAL” IN YOUR FUNCTION FILE

Comments in lines 2, …: – Words in line 2 are searched when lookfor is employed – called the “H1” line. – Comments in lines 2, 3, … are returned when help name is executed, helpful to remember.

Variables: Local vs Global Usually, once created, variables are available in the workspace until cleared Functions create their own workspace with their own local variables distinct from those in the original workspace – Functions cannot modify variables within the original workspace – except through outputs – Exception – global variables can span both workspaces and be manipulated in both

Example Function: DEG2RAD

Another Example Compute the area and perimeter of a right triangle as a function of its base and height: Area = 0.5 * base * height Perimeter = base + height + hypotenuse

First, just do the area computation:

Add the perimeter computation:

Example: my personal plotter

Typical Errors for Functions Too few inputs

Too many inputs Too many outputs Wrong input type – funny result

DIFFUSION Diffusion – is the movement of matter driven by chemical and thermal processes such as concentration gradients and heating. Both are needed as it is an activation controlled process. Atoms will diffuse down a concentration gradient provided they have overcome the activation energy needed for the process. Copper atoms will diffuse into the Nickel until an equal concentration is Achieved. Remember that Cu-Ni system Is one of complete solid solubility. System is NON STEADY STATE.

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 and Temperature - Plots Diffusion increased with temperature It is activation controlled so follows:- D=Do exp (-E/kT) Where D = Diffusivity(m 2 /sec) Do = Constant E = activation energy k = Boltzman’s Constant T = temperature in oK k= 13.8x J/atom.K lnD=lnDo – Q/RT Q – cal/mole R – cal/mole.K y= c +mx Slope = Q/R if ln D plotted against 1/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

Functions for Project Function to calculate time? What input data? Form of output? Graph, number?

TEAMS On Tuesday, March 11, need team names and team members to be handed in.

Thursdays March 6 and March13 This Thursday meet in DISCOVERY LAB(ECL) Thursday March 13, QUIZ on all form last quiz. Today – go to discovery lab and run function “degrad”.