AP3114 Lecture WK1 Introduction

Embed Size (px)

DESCRIPTION

Physics

Citation preview

AP3114/Computational Methods for Physicists and Materials Engineers

AP3114/Computational Methods for Physicists and Materials EngineersDr. Jun FanAug. 31, 2015Typical Problems in Physics and Materials Engineering& Introduction to Scilab

Questions about youWhich year are you in, 1, 2, 3, or 4?

Do you have any programming experience?

// year 1 2 3 and 4clf; x=[1, 2, 3, 4]; // number of students in year 1/2/3/4 n1=[2, 12, 16, 20]; // number of students who have programming experience n2=[0 5 8 16]; bar(x, [n1', n2']) xlabel('Year','fontsize',6) ylabel('No. of students','fontsize',6)Problems in Math, Physics and Materials Engineering1. Linear equations2. Free Fall3. Electric Current4. Cantilever Beam5. Diffusion 6. Random Events

1. Linear Equations

Scilab

2. Free Fallt=0, v=0,Case 1. No air resistance

Case 2. Resistance proportional to the linear power of velocity

Case 3. Resistance proportional to the second power of the velocity

2. Free FallWhat is the status of the particle at t=5? (Given k=0.2, g=9.81m/s2)

2. Free Fall

2. Free Fall

Computation ResultsCase 1Case 2Case 3Case 1Case 2Case 33. Electric CurrentA single, closed-loop electrical circuitThe loop contains a voltage source V (battery), a resistor R (energy dissipation device), an inductor L (an energy storage device),A switch that is instantaneously closed at time t=0

Solution:

3. Electric CurrentV=1; R=1; L=1; t=0:0.01:6; i=(V/R)*(1-exp(-R.*t/L));figure;plot(t,i,'ro');xlabel('time, t','fontsize',6),ylabel('current, i','fontsize',6)

4. Cantilever Beam

The Olive View Hospital damaged in the 1971 San Fernando earthquake (original image from the EqIIS Collection)

4. Cantilever BeamFor a uniformly loaded span of a cantilever beam attached to a wall at x = 0 with the free end at x = L, the formula for the vertical displacement from y = 0 under the loaded condition, with y the coordinate in the direction opposite that of the load, can be written as follows:

whereE is a material property known as the modulus of elasticity;I is a geometric property of the cross-section of the beam known as the moment of inertia; L is the length; w is the load per unit width of the beam.

4. Cantilever beamx=0:0.01:1;y=-(x.^4-4*x.^3+6*x.^2);plot(x,y)xlabel('x','fontsize',6)ylabel('y','fontsize',6)title('Cantilever Beam')plot([0 1],[0 0],'linewidth',2)legend('Uniformly loaded beam,unloaded)

5.

Diffusion equation:

5. Diffusionx=1:1:100; dt=0.05; c=zeros(100,1); c(1)=1; figure; for t=1:1:3000 for i=2:1:99 d(i)=(c(i+1)+c(i-1)-2*c(i))*dt+c(i); end d(100)=d(99); d(1)=1-sum(d(2:100)); c=d; if pmodulo(t,1000)==0 then plot(x,c); end end

c(x,t)xt1t3t2Results

6. Random walk (Markov process)A drunk wanders down a street that has six intersections. His home is at interaction 1, and his favorite Internet caf is at intersection 6. At each intersection other than his home or the caf, he moves in the direction of the caf with probability 2/3 and in the direction of his home with probability 1/3. We would like to know the chances of the drunk ending up at home or in the caf is. He starts at a given corner.

HomeCafe362145P=1/3P=2/36. Random walk (Markov process)We represent the probabilities of being in these states a six-component state vector X(t), where Xi(t) is the probability of him being at intersection i at moment t. The components of X(t) must sum to 1, since he has to be in one of these states.

HomeCafe362145P=1/3P=2/3

Transition probability matrix6. Random walk (Markov process)

Results: 48% at home, 52% at CafeScientific softwareTwo categories of general scientific softwareComputer algebra systems that perform symbolic computations: Maple, Mathematica, Maxima, Axiom, and MuPad General purpose numerical systems performing numerical computations and designed specifically for scientific applications: Matlab, Scilab (free)ScilabA large software package containing 13,000 files, more than 400,000 lines of source code, 70,000 lines of Scilab code, 80,000 lines of online help, and 18,000 lines of configuration files, includingElementary functions of scientific calculationLinear algebra, spare matricesPolynomials and rational functionsClassic and robust control, optimizationsNonlinear methods (optimization, ODE solver, Scicos dynamic systems modeler and simulator)Signal processingRandom sampling and statisticsGraphs, graphics, animation

Programmable CalculatorScilabwww.scilab.org

Download (select a version for your own computer, Windows/Mac/Linux) & installhttp://www.scilab.org/download/5.5.1A copy for Windows has been upload to Canvas

WindowsMacLinuxReferencehttp://www.scilab.org/resources/documentation/tutorialsIntroduction to Scilab (introscilab.pdf)Scilab for very beginners (Scilab_beginners.pdf)

Scilab interface

Start -> ScilabDirectory& filesCommand historyVariablesCommand Input InterfaceHelpTo get help, type help> help derivative

Editor

>editorSave as *.sce fileTo run: exec(filename.sce)Who is this?Ihear, I forgetIsee, I rememberIdo, I learn

26Creating real variablesElementary mathematical operators

Variable namesVariable names may be as long as the user wants, but only the first 24 characters are taken into account in Scilab.Case sensitivea to z, A to Z, 0 to 9, %, _, #, !, $, ?Starting with % has special meaning, such as %piCase sensitive VariablesFor example

Comments and continuation linesComments: Any line which begins with two slashes//Continuation lines: any line which ends with two dots..

List of Elementary Mathematical FunctionsTrigonometry

Other functions

Elementary mathematical functionsFor example,Lets test check it in Scilab:

Pre-defined mathematical variablesIn Scilab, several mathematical variables are pre-defined, whose name starts with a percent % character.

BooleansBoolean variables can store true (%t, or %T) or false (%f, or %F) values.

Complex numbers

In Scilab, %i represents the mathematical imaginary number i?

is used to compute the conjugate real returns real part imag returns imaginary part

IntegersInteger type:

Number of bits used to store an integer and the range of value:n-bit signed integer: [-2n-1, 2n-1-1]n-bit unsigned integer: [0, 2n-1]

Conversions between integers

Types of integers returned by the inttype function

Scilab integer conversion functions:Circular integers and portability issues

Different from other mathematical packages, such as Octave or Matlab: if an integer is at the upper limit, the next integer stays at the upper limitThe Scilab circular way allows for a greater flexibility in the processing of integers, since it allows to write algorithms with fewer if statementsThe ans variable

When we make a computation and do not store the result into an output variable, the result is stored in the default ans variableStrings

Strings can be stored in variables, provided that they are delimited by double quotes .+ can operate strings.Dynamic type of variables

Scilab allows to change the type of a variable dynamically. The following example shows that we first create a real value, and then put a string variable in it:Home Work-1

Due: 9am, Sep 7, 2015Late policy: 10% off per day To be submitted online to Canvas.

Exercises (I)

Exercises (II)

Exercises (III)

What will you get by executing the following?

Exercises (IV)What will you get by executing the following?

Exercises (V)What will you get by executing the following?

Exercises (VI)What will you get by executing the following?

Exercises (VII)Determine the value of the following expressions yourself before checking your answers using Scilab

Exercises (VIII)Given that a=[1 0 2] and b=[0 2 2], determine the value of the following expressions. Check your answers with Scilab