Finite Element

© All Rights Reserved

6 views

Finite Element

© All Rights Reserved

- ucinet
- Tetris Tutorial in C++ Platform Independent Focused in Game Logic for Beginners _ Javilop
- lk
- F5 Maths Annual Scheme of Work_2012
- Criteria of Savage (Opportunity Cost)
- Ochi2
- hw_2
- posterjoiner
- 3a Laplace
- Survey of Sparse and Non-Sparse Methods in Source Separation
- 10.1.1.114.6442
- Quiz A(n)
- matlab1
- Probability Impact Analysis
- 1 MAC 2013
- p250-fredman
- Preview Lulu Staad 2005
- 1280notes-6.pdf
- ELEMENTARY LINEAR ALGEBRA.pdf
- unit 1 lesson 2 with work

You are on page 1of 5

We will be using Matlab as our computing environment. So Ill follow our text and begin with a

review of some of the features of this program. An important consideration for our purposes is that

Matlab has been written so as to handle matrices with ease basically every variable we use is a

matrix with ordinary scalars just 1 by 1 matrices.

>> format compact

>> %entering a matrix

>> a=[1 2 3; 4 7 9; 5 4 3]

a =

1

2

3

4

7

9

5

4

3

>> b=[2 4;1 9;3 6];

>> %matrix multiplication

>> a*b

ans =

13

40

42

133

23

74

>> %inversion

>> c=inv(a)

c =

2.5000

-1.0000

0.5000

-5.5000

2.0000

-0.5000

3.1667

-1.0000

0.1667

>> %check

>> c*a

ans =

1.0000

0.0000

-0.0000

-0.0000

1.0000

-0.0000

0.0000

0.0000

1.0000

>> %linear equation solution ax=f

>> f=[1;2;3];

>> x=a\f

x =

2.0000

-3.0000

1.6667

>> %check

>> a*x

ans =

1.0000

2.0000

3.0000

>> %matrix decomposition pa=lu

>> [l,u,p]=lu(a)

1

l =

1.0000

0.8000

0.2000

0

1.0000

0.3158

0

0

1.0000

5.0000

0

0

4.0000

3.8000

0

3.0000

6.6000

0.3158

u =

p =

0

0

1

0

1

0

1

0

0

>> %check (note: the conjugate transpose of a matrix m is produced by m)

>> a-p*l*u

ans =

0

0

0

0

0

0

0

0

0

>> %matrix decomposition a=qr (q orthogonal, r upper triangular)

>> [q,r]=qr(a)

q =

-0.1543

-0.2630

-0.9524

-0.6172

-0.7270

0.3008

-0.7715

0.6342

-0.0501

r =

-6.4807

-7.7152

-8.3324

0

-3.0783

-5.4296

0

0

-0.3008

>> %checks: qq=I

>> q*q

ans =

1.0000

-0.0000

-0.0000

-0.0000

1.0000

-0.0000

-0.0000

-0.0000

1.0000

>> a-q*r

ans =

1.0e-014 *

0.0333

0.2665

0.5329

0

0.0888

0.1776

0.0888

0.2665

0.5329

Matlab has a large built-in library of functions. Most of these take a matrix argument. That is, if X

is an m n real matrix, and f : R R is some built-in function like sine, cos, exp, etc., then f (X)

is an m n matrix with elements f (xij ). Similar statements apply of functions defined for complex

values. In addition to the usual elementary functions Matlab supplies many special functions like

Bessel functions, etc.

The feature of Matlab that will be of most use to us is the possibility of creating new functions

2

using Matlabs C-like programming language. These new functions can use all of Matlabs built-in

capabilities. As an example, lets create a function that does a least squares fit of a straight line to

a n 2 data array

x1 y1

..

..

.

.

xn

yn

the line y = ax + b to this data in such a way that the sum of the squares of

n

the errors, E(a, b) = i=1 (yi axi b)2 =minimum. Recall from your Calculus courses that we

find the minimum of E by setting the partial derivatives

E

= 0.

b

E

= 0,

a

This gives the system of equations

nb + (

Pn

i=1

xi )a

Pn

Pn

( i=1 xi )b + ( i=1 x2i )a

=

=

Pn

i=1

Pn

i=1

yi

xi yi

First, lets create some data and store it in a disk file using the built-in function fprintf which

should be familiar to C programmers:

>> x=[20.5 20.6 20.65 20.75 20.8 20.85 20.9 21];

>> y=[118.1 118.25 118.2 118.4 118.4 118.5 118.45 118.5];

>> fid=fopen(data.txt,w+);

>> fprintf(fid,%10.5f %10.5f\n, [x;y]);

>> fclose(fid);

%============================

%this results in the file

20.50000 118.10000

20.60000 118.25000

20.65000 118.20000

20.75000 118.40000

20.80000 118.40000

20.85000 118.50000

20.90000 118.45000

21.00000 118.50000

%============================

In programming our function, well suppose that the vectors x and y are available in Matlab. We

could program our function to read them in, but well assume they have already been read into

Matlab by the built-in function fscanf. (There other functions available for reading and writing

data try help iofun.) Heres how to use fscanf.

>> yy=fscanf(fid,%f %f,[2,inf]);

>> yy=yy

>> x=yy(:,1); y=yy(:,2);

3

>> x

x =

20.5000

20.6000

20.6500

20.7500

20.8000

20.8500

20.9000

21.0000

>> y

y =

118.1000

118.2500

118.2000

118.4000

118.4000

118.5000

118.4500

118.5000

>> fclose(fid)

ans =

0

Now we create our program file using any convenient text editor or the one built into Matlab.

function [av]=leastsq(x,y)

% function [a,b]=leastsq(x,y)

% Input: x, y vectors of same length, n

% Output: av=[b;a] coefficients in best fit straight line y=ax+b

n=max(size(x)); m=max(size(y));

if(n~=m) error(input vectors not same size); end

c=[n sum(x);sum(x) sum(x.^2)];

z=[sum(y); dot(x,y)];

av=c\z;

Notice how we use the functions max, size, error, sum, dot, and the matrix inverter \. Think of how

much longer our function would be if we had to create all these ourselves. Running this program on

the data gives:

>> av=leastsq(x,y)

av =

100.8000

0.8455

>> xx=linspace(20.4,21.0);

>> yy=av(2)*xx+av(1);

>> plot(x,y,o,xx,yy)

4

118.6

118.5

118.4

118.3

118.2

118.1

118

20.3

20.4

20.5

20.6

20.7

20.8

20.9

21

- ucinetUploaded byLuckyClover
- Tetris Tutorial in C++ Platform Independent Focused in Game Logic for Beginners _ JavilopUploaded byziedus
- lkUploaded by53melmel
- F5 Maths Annual Scheme of Work_2012Uploaded byJoyce Tay
- Criteria of Savage (Opportunity Cost)Uploaded bydorasancez
- Ochi2Uploaded byEgwuatu Uchenna
- hw_2Uploaded byRohit Kishore
- posterjoinerUploaded byMaria Fernanda Velasco Duffy
- 3a LaplaceUploaded byAinur Sya Irah
- Survey of Sparse and Non-Sparse Methods in Source SeparationUploaded byctzag
- 10.1.1.114.6442Uploaded byAlam Mohammad Parvez Saifi
- Quiz A(n)Uploaded byHoàng Minh Măng
- matlab1Uploaded byTanzid Sultan
- Probability Impact AnalysisUploaded byMatthew Lynch
- 1 MAC 2013Uploaded byfadariah-1
- p250-fredmanUploaded byasdf
- Preview Lulu Staad 2005Uploaded bymohanty_anantakumar6332
- 1280notes-6.pdfUploaded byRadu Constantinescu
- ELEMENTARY LINEAR ALGEBRA.pdfUploaded byGeologi
- unit 1 lesson 2 with workUploaded byapi-366301098
- The Apocalypse of Our Lord Jesus ChristUploaded byThe_buzzcut
- Tutorial 2Uploaded bySelvanathan Ramasamy
- 03 Quarter Car Model SimUploaded byJuan Pablo
- Math Review HandoutUploaded byDavid Reaver
- Math Review HandoutUploaded byDavid Reaver
- Basic Prnciples of Plates and ShellsUploaded byJunaidAhmed
- 83074004 Quid e Azam Test Cs MphilUploaded byسردار داہود جان
- Computer-Methods-in-Applied-Mechanics-and-Engineering-Volume-3-issue-1-1974-doi-10.1016_0045-78257490045-0-H.-J.-Schek-The-force-density-method-for-form-finding-and-computation-of-gener.pdfUploaded byvo quan
- Jay OoPmUploaded byJagdish Padhy
- quant. questions 700-800Uploaded byMatteo Carbone

- Structural MechanicsUploaded byDirkPons
- 1305635132_538742Uploaded byHasen Bebba
- What Plumbing Designers Need to Know About Valves, Part 2.pdfUploaded byHasen Bebba
- Basic Operation and Function Of_ControlValvesUploaded byAndrew Bailey
- Grease processingUploaded byRishikesh Awale
- me471s03_syUploaded byHasen Bebba
- ABB Control ValveUploaded byHafzi
- Advantages of Globe ValvesUploaded byJohn Rey Tumala
- Brainstorming (1)Uploaded byAli M. Chehadeh
- CDC UP Project Management Plan TemplateUploaded byMими Кољушкова
- me471s03_q2_ansUploaded byHasen Bebba
- me471s03_q1_ansUploaded byHasen Bebba
- me471s03_lec11aUploaded byHasen Bebba
- me471s03_lec10Uploaded byHasen Bebba
- me471s03_lec09Uploaded byHasen Bebba
- me471s03_lec08Uploaded byHasen Bebba
- me471s03_lec07Uploaded byHasen Bebba
- me471s03_lec06Uploaded byHasen Bebba
- me471s03_lec05Uploaded byHasen Bebba
- me471s03_lec04Uploaded byHasen Bebba
- Me471s03 Laplace ExampUploaded byHasen Bebba
- me471_prob5_8Uploaded byHasen Bebba
- me471_lec03Uploaded byHasen Bebba
- me471_lec02Uploaded byHasen Bebba
- me471_lec01Uploaded byHasen Bebba
- me471_hwk06ansUploaded byHasen Bebba
- me471_hwk05ansUploaded byHasen Bebba
- me471_hwk04ansUploaded byHasen Bebba

- QT 600Uploaded byInnocent Ramaboka
- Further StatisticsUploaded byrtb101
- Product & Brand MgmtUploaded byAmit Jangid
- 2010 2011 Milano CatalogUploaded bySharoon Saleem
- Malhotra Mr05 Ppt 19Uploaded byABHISHEK CHAKRABORTY
- Application of Pontryagin’s Maximum Principles and RungeKutta Methods in Optimal Control ProblemsUploaded byIOSRjournal
- Practice Problems 6.20.2011 KEYUploaded bymitmit
- Approximating the Bell-shaped Function based on Combining Hedge Algebras and Particle Swarm OptimizationUploaded byIJEID :: www.ijeid.com
- SPSS-Tutorial-Cluster-AnalysisUploaded byAnirban Bhowmick
- m4l25Uploaded byanon_702462456
- M02 Functions and Equations (1)Uploaded byNeha Deshpande
- Tesi a.dmytrivUploaded byPipino Il Breve
- Dynamic Response 2Uploaded byAlex Javier
- Definite Integration CalculatorUploaded bytutorciecleteam
- Integration TheoryUploaded bymarios pappas
- Data Science Syllabus.docxUploaded bymohammed habeeb Vulla
- Msci603 f2018 6 IntroipUploaded byMridul Gupta
- 8.Project Quality ManagementUploaded bysatstar
- 10_ALGEBRA.pdfUploaded byFuad_Khafizov_5342
- MARKETING RESEARCHUploaded bysandeepkhatak
- Module 10 Graf FunctionUploaded byHelen Pappu
- Assignment 2 Matlab Q2Uploaded byBazin Tsegaye
- Vector CalculusUploaded byncharala
- Hyperbolic Function - WikipediaUploaded byMadhav Sethia
- AHB Solutions C4 June 2013Uploaded byDon Wilson
- GB Final ReportUploaded bykotharideep
- syllabUploaded bySrivathson Eswaran
- MiniQueuingUploaded bymhamad3
- A User-friendly Introduction to Lebesgue Measure and IntegrationUploaded bygomson
- Glossary of Six Sigma Terms and AcronymsUploaded byAmlen Singha

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.