SlideShare a Scribd company logo
1 of 7
Download to read offline
Sample Assignment For Reference Only
Finite Element Solver of a Poisson Equation in One Dimension
We have an equation:
, 0 1
With g(x) defined as:
2 sin 4 1 cos 1 sin
With Dirichlet boundary condition:
0 0,
1
0
Assignment 1
We have the function:
1 sin .
Then:
2sin 1 1 cos
2 sin 2 cos 1 2 1 cos 1 sin
2 sin 4 1 cos 1 sin
So:
Also:
0 0 1 sin 0 1 sin 0 0,
1
2sin 1 1 1 1 cos 0
We wrote the next matlab function to plot this analytical solution:
clear all;
clc;
% -- function u(x)
x=0:0.001:1;
ux=-(x-1).^2.*sin(pi*x);
figure(1)
plot(x,ux)
xlabel('x')
ylabel('u(x)')
Sample Assignment For Reference Only
And here is the figure for u(x)
Assignment 2.
Here, we can write the numerical scheme to get the algorithm for numerical solution of our equation.
We know, that the second derivative at some point i can be represented as next:
2
∆
Thus, we can write en equation of form:
1; 2; 1
2∆
∗ ∆
So, as we see we can write the next equation:
Where:
- A is tridiagonal matrix (non-zero elements only on main diagonal and on elements up and beneath from
it).
- u is unknown vector of function we looking at.
- g is a vector with function g(x) values at points xi.
Assignment 3.
The trapezoidal rule can be written is the next way :
2
Sample Assignment For Reference Only
We can write the our intermediate matrix Sei which appear for every step and every element ei as the next
(here we use the result for matrix A from previous part):
1 1 1
1 1
Using previous part and trapezoidal rule we can write the vector fei as the next:
2
Assignment 4.
The next step will be to assemble all our element matrixes Sei in one global matrices, for example if we only
have 2 nodes in our system we can assemble matrices Se1 and Se2 in the next way:
1 1 1
1 1
,
1 1 1
1 1
, ,
1/ 1/ 0
1/ 1/ 1/ 1/
0 1/ 1/
So, we see that for N=2 nodes we have 3x3 matrix , this will work also in the general case when we have N
nodes and (N+1)x(N+1) global matrix.
The same induction we can build for vector fei, for example for 2 nodes we will have:
2
,
2
,
2
2
Assignment 5.
This was done as additional function in Matlab:
function f=GenerateMesh(xo,xe,N)
% --- create the mesh of N+1 point in range x0 ... xe
dx=(xe-xo)/N;
for i=1:N+1
x(i)=xo+dx*(i-1);
end
f=x;
end
Assignment 6.
This was done as additional function in Matlab:
function f=SourceFct(xi)
% -- gives value of source function at xi
f=2*sin(pi*xi)+4*pi*(xi-1)*cos(pi*xi)-pi^2*(xi-1)^2*sin(pi*xi);
end
Assignment 7.
Sample Assignment For Reference Only
This was done as additional function in Matlab:
function f=GenerateTopology(N)
% -- generate topology matrix
f=zeros(N,2);
for i=1:N
f(i,1)=i;
f(i,2)=i+1;
end
end
Assignment 8.
This was done as additional function in Matlab:
function f=GenerateElementMatrix(xi,xi1)
% -- input , the values of x(i) and x(i+1)
Sei=[1 -1; -1 1];
Sei=Sei/(xi1-xi);
f=Sei;
end
Assignment 9.
This was done as additional function in Matlab:
function f=GenerateElementVector(xi,xi1)
gi=SourceFct(xi);
gi1=SourceFct(xi1);
f=[gi*(xi1-xi)/2;gi1*(xi1-xi)/2];
end
Assignment 10.
This was done as additional function in Matlab:
function f=AssembleMatrix(xo,xe,N)
S=zeros(N+1,N+1);
x=GenerateMesh(xo,xe,N);
elmat=GenerateTopology(N);
for i=1:N
Sei=GenerateElementMatrix(x(i),x(i+1));
for j=1:2
for k=1:2
S(elmat(i,j),elmat(i,k))=S(elmat(i,j),elmat(i,k))+Sei(j,k);
end
end
end
f=S;
end
Assignment 11.
This was done as additional function in Matlab:
function f=AssembleVector(xo,xe,N)
fv=zeros(N+1,1);
x=GenerateMesh(xo,xe,N);
elmat=GenerateTopology(N);
for i=1:N
fei=GenerateElementVector(x(i),x(i+1));
Sample Assignment For Reference Only
for j=1:2
fv(elmat(i,j))=fv(elmat(i,j))+fei(j);
end
end
f=fv;
end
Assignment 12.
This was reached by adding next lines to main program when we calculate the matrix S and vector f before
use them to solve en equation :
% boundary ---
S(1,1)=1;
S(1,2)=0;
f(1)=0;
Assignment 13.
We run our main program for N=100 and got the next visualization for S matrix as
Assignment 14.
Here is the graphs where we have two solutions, analytical u(x) from first part and numerical for N=8, and
N=32.
N=8 N=32
Sample Assignment For Reference Only
As we see – for more number of nodes we have better convergence between two solutions, analytical and
numerical.
Elective Part
Part 1
Lets try to write analytical solution as:
1 sin 2
This will give the same result for second derivative as we know that 2 0
So, we after changes in main and additional function we will get the result.
As we see the results very unclose – this can be explained that we need change not only analytical solution
but also the boundary conditions.
Part 2
To compare results for different number of nodes we can write the loop for different N=2,4,8,16,… etc. On
every loop we calculate the numerical solution and the error (largest values for mesh).
Sample Assignment For Reference Only
And we got the next graph for norm of error vs. number of nodes (see q_err.m file):
As we see , in logarithmic axes we have linear dependence for logarithm of norm of error from logarithm from
number of nodes, this leads from the way we wrote our equations using linear (first order) Lagrangian shape
functions.
Part 3
Here we changed the program by adding to last element in vector f the value:
, 1/
So, in this way we got the next graph with different numerical solutions (for N=16) for different values of α
(see q_neumann.m for script):
As we see – with increasing of α we get the increasing of left boundary of function

More Related Content

What's hot

Exponential and logarithmic functions
Exponential and logarithmic functionsExponential and logarithmic functions
Exponential and logarithmic functionsNjabulo Nkabinde
 
Matlab ploting
Matlab plotingMatlab ploting
Matlab plotingAmeen San
 
Exponential functions
Exponential functionsExponential functions
Exponential functionsRon Eick
 
Functions
FunctionsFunctions
FunctionsJJkedst
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and PolynomialAroosa Rajput
 
2.2 Polynomial Function Notes
2.2 Polynomial Function Notes2.2 Polynomial Function Notes
2.2 Polynomial Function Noteslgemgnani
 
Lesson 10 derivative of exponential functions
Lesson 10 derivative of exponential functionsLesson 10 derivative of exponential functions
Lesson 10 derivative of exponential functionsRnold Wilson
 
Algebra lesson 4.2 zeroes of quadratic functions
Algebra lesson 4.2 zeroes of quadratic functionsAlgebra lesson 4.2 zeroes of quadratic functions
Algebra lesson 4.2 zeroes of quadratic functionspipamutuc
 
125 4.1 through 4.5
125 4.1 through 4.5125 4.1 through 4.5
125 4.1 through 4.5Jeneva Clark
 
Module 2 lesson 4 notes
Module 2 lesson 4 notesModule 2 lesson 4 notes
Module 2 lesson 4 notestoni dimella
 
Engineering procedure
Engineering procedureEngineering procedure
Engineering procedureVinny Costa
 
Exponential Functions
Exponential FunctionsExponential Functions
Exponential Functionsitutor
 

What's hot (19)

Chapter 11
Chapter 11Chapter 11
Chapter 11
 
7.2 abs value function
7.2 abs value function7.2 abs value function
7.2 abs value function
 
Exponential and logarithmic functions
Exponential and logarithmic functionsExponential and logarithmic functions
Exponential and logarithmic functions
 
Matlab ploting
Matlab plotingMatlab ploting
Matlab ploting
 
Exponential functions
Exponential functionsExponential functions
Exponential functions
 
Tutorial 2
Tutorial     2Tutorial     2
Tutorial 2
 
Functions
FunctionsFunctions
Functions
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and Polynomial
 
2.2 Polynomial Function Notes
2.2 Polynomial Function Notes2.2 Polynomial Function Notes
2.2 Polynomial Function Notes
 
1.2 matlab numerical data
1.2  matlab numerical data1.2  matlab numerical data
1.2 matlab numerical data
 
Lesson 10 derivative of exponential functions
Lesson 10 derivative of exponential functionsLesson 10 derivative of exponential functions
Lesson 10 derivative of exponential functions
 
Algebra lesson 4.2 zeroes of quadratic functions
Algebra lesson 4.2 zeroes of quadratic functionsAlgebra lesson 4.2 zeroes of quadratic functions
Algebra lesson 4.2 zeroes of quadratic functions
 
125 4.1 through 4.5
125 4.1 through 4.5125 4.1 through 4.5
125 4.1 through 4.5
 
Section9 stochastic
Section9 stochasticSection9 stochastic
Section9 stochastic
 
Module 2 lesson 4 notes
Module 2 lesson 4 notesModule 2 lesson 4 notes
Module 2 lesson 4 notes
 
Engineering procedure
Engineering procedureEngineering procedure
Engineering procedure
 
Boolean algebra
Boolean algebraBoolean algebra
Boolean algebra
 
Exponential Functions
Exponential FunctionsExponential Functions
Exponential Functions
 
S1 0 derivadas
S1 0 derivadasS1 0 derivadas
S1 0 derivadas
 

Similar to Matlab Sample Assignment Solution

06_finite_elements_basics.ppt
06_finite_elements_basics.ppt06_finite_elements_basics.ppt
06_finite_elements_basics.pptAditya765321
 
A MATLAB project on LCR circuits
A MATLAB project on LCR circuitsA MATLAB project on LCR circuits
A MATLAB project on LCR circuitssvrohith 9
 
MATLAB ODE
MATLAB ODEMATLAB ODE
MATLAB ODEKris014
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxanhlodge
 
Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2Scilab
 
Differential Equations Homework Help
Differential Equations Homework HelpDifferential Equations Homework Help
Differential Equations Homework HelpMath Homework Solver
 
Introduction to Functions
Introduction to FunctionsIntroduction to Functions
Introduction to FunctionsMelanie Loslo
 
Metodos jacobi y gauss seidel
Metodos jacobi y gauss seidelMetodos jacobi y gauss seidel
Metodos jacobi y gauss seidelCesar Mendoza
 
Metodos jacobi y gauss seidel
Metodos jacobi y gauss seidelMetodos jacobi y gauss seidel
Metodos jacobi y gauss seidelCesar Mendoza
 
Probabilistic approach to prime counting
Probabilistic approach to prime countingProbabilistic approach to prime counting
Probabilistic approach to prime countingChris De Corte
 
Programming with effects - Graham Hutton
Programming with effects - Graham HuttonProgramming with effects - Graham Hutton
Programming with effects - Graham HuttonWen-Shih Chao
 
DSP_FOEHU - MATLAB 03 - The z-Transform
DSP_FOEHU - MATLAB 03 - The z-TransformDSP_FOEHU - MATLAB 03 - The z-Transform
DSP_FOEHU - MATLAB 03 - The z-TransformAmr E. Mohamed
 

Similar to Matlab Sample Assignment Solution (20)

project final
project finalproject final
project final
 
Signals and Systems Homework Help.pptx
Signals and Systems Homework Help.pptxSignals and Systems Homework Help.pptx
Signals and Systems Homework Help.pptx
 
06_finite_elements_basics.ppt
06_finite_elements_basics.ppt06_finite_elements_basics.ppt
06_finite_elements_basics.ppt
 
5994944.ppt
5994944.ppt5994944.ppt
5994944.ppt
 
A MATLAB project on LCR circuits
A MATLAB project on LCR circuitsA MATLAB project on LCR circuits
A MATLAB project on LCR circuits
 
MATLAB ODE
MATLAB ODEMATLAB ODE
MATLAB ODE
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
 
Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2
 
Matlab calculus
Matlab calculusMatlab calculus
Matlab calculus
 
Differential Equations Homework Help
Differential Equations Homework HelpDifferential Equations Homework Help
Differential Equations Homework Help
 
Introduction to Functions
Introduction to FunctionsIntroduction to Functions
Introduction to Functions
 
Computer Network Homework Help
Computer Network Homework HelpComputer Network Homework Help
Computer Network Homework Help
 
Statistical Method In Economics
Statistical Method In EconomicsStatistical Method In Economics
Statistical Method In Economics
 
Metodos jacobi y gauss seidel
Metodos jacobi y gauss seidelMetodos jacobi y gauss seidel
Metodos jacobi y gauss seidel
 
Metodos jacobi y gauss seidel
Metodos jacobi y gauss seidelMetodos jacobi y gauss seidel
Metodos jacobi y gauss seidel
 
Probabilistic approach to prime counting
Probabilistic approach to prime countingProbabilistic approach to prime counting
Probabilistic approach to prime counting
 
Programming with effects - Graham Hutton
Programming with effects - Graham HuttonProgramming with effects - Graham Hutton
Programming with effects - Graham Hutton
 
DSP_FOEHU - MATLAB 03 - The z-Transform
DSP_FOEHU - MATLAB 03 - The z-TransformDSP_FOEHU - MATLAB 03 - The z-Transform
DSP_FOEHU - MATLAB 03 - The z-Transform
 
Assignment 2 solution acs
Assignment 2 solution acsAssignment 2 solution acs
Assignment 2 solution acs
 
ML ALL in one (1).pdf
ML ALL in one (1).pdfML ALL in one (1).pdf
ML ALL in one (1).pdf
 

More from All Assignment Experts

More from All Assignment Experts (8)

ENGINEERING PROJECT – CONVEYOR BLOCKAGE DETECTION
ENGINEERING PROJECT – CONVEYOR BLOCKAGE DETECTIONENGINEERING PROJECT – CONVEYOR BLOCKAGE DETECTION
ENGINEERING PROJECT – CONVEYOR BLOCKAGE DETECTION
 
Business strategy Assignment Help
Business strategy Assignment HelpBusiness strategy Assignment Help
Business strategy Assignment Help
 
Business laws sample assignment
Business laws sample assignmentBusiness laws sample assignment
Business laws sample assignment
 
Essay writing sample_assignment
Essay writing sample_assignmentEssay writing sample_assignment
Essay writing sample_assignment
 
Mathematics sample assignment
Mathematics sample assignmentMathematics sample assignment
Mathematics sample assignment
 
Civil Engineering Sample Assignment Solution
Civil Engineering Sample Assignment Solution Civil Engineering Sample Assignment Solution
Civil Engineering Sample Assignment Solution
 
Electrical Engineering Sample Assignment
Electrical Engineering Sample AssignmentElectrical Engineering Sample Assignment
Electrical Engineering Sample Assignment
 
Matlab Sample Assignment Solution
Matlab Sample Assignment SolutionMatlab Sample Assignment Solution
Matlab Sample Assignment Solution
 

Recently uploaded

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 

Recently uploaded (20)

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 

Matlab Sample Assignment Solution

  • 1. Sample Assignment For Reference Only Finite Element Solver of a Poisson Equation in One Dimension We have an equation: , 0 1 With g(x) defined as: 2 sin 4 1 cos 1 sin With Dirichlet boundary condition: 0 0, 1 0 Assignment 1 We have the function: 1 sin . Then: 2sin 1 1 cos 2 sin 2 cos 1 2 1 cos 1 sin 2 sin 4 1 cos 1 sin So: Also: 0 0 1 sin 0 1 sin 0 0, 1 2sin 1 1 1 1 cos 0 We wrote the next matlab function to plot this analytical solution: clear all; clc; % -- function u(x) x=0:0.001:1; ux=-(x-1).^2.*sin(pi*x); figure(1) plot(x,ux) xlabel('x') ylabel('u(x)')
  • 2. Sample Assignment For Reference Only And here is the figure for u(x) Assignment 2. Here, we can write the numerical scheme to get the algorithm for numerical solution of our equation. We know, that the second derivative at some point i can be represented as next: 2 ∆ Thus, we can write en equation of form: 1; 2; 1 2∆ ∗ ∆ So, as we see we can write the next equation: Where: - A is tridiagonal matrix (non-zero elements only on main diagonal and on elements up and beneath from it). - u is unknown vector of function we looking at. - g is a vector with function g(x) values at points xi. Assignment 3. The trapezoidal rule can be written is the next way : 2
  • 3. Sample Assignment For Reference Only We can write the our intermediate matrix Sei which appear for every step and every element ei as the next (here we use the result for matrix A from previous part): 1 1 1 1 1 Using previous part and trapezoidal rule we can write the vector fei as the next: 2 Assignment 4. The next step will be to assemble all our element matrixes Sei in one global matrices, for example if we only have 2 nodes in our system we can assemble matrices Se1 and Se2 in the next way: 1 1 1 1 1 , 1 1 1 1 1 , , 1/ 1/ 0 1/ 1/ 1/ 1/ 0 1/ 1/ So, we see that for N=2 nodes we have 3x3 matrix , this will work also in the general case when we have N nodes and (N+1)x(N+1) global matrix. The same induction we can build for vector fei, for example for 2 nodes we will have: 2 , 2 , 2 2 Assignment 5. This was done as additional function in Matlab: function f=GenerateMesh(xo,xe,N) % --- create the mesh of N+1 point in range x0 ... xe dx=(xe-xo)/N; for i=1:N+1 x(i)=xo+dx*(i-1); end f=x; end Assignment 6. This was done as additional function in Matlab: function f=SourceFct(xi) % -- gives value of source function at xi f=2*sin(pi*xi)+4*pi*(xi-1)*cos(pi*xi)-pi^2*(xi-1)^2*sin(pi*xi); end Assignment 7.
  • 4. Sample Assignment For Reference Only This was done as additional function in Matlab: function f=GenerateTopology(N) % -- generate topology matrix f=zeros(N,2); for i=1:N f(i,1)=i; f(i,2)=i+1; end end Assignment 8. This was done as additional function in Matlab: function f=GenerateElementMatrix(xi,xi1) % -- input , the values of x(i) and x(i+1) Sei=[1 -1; -1 1]; Sei=Sei/(xi1-xi); f=Sei; end Assignment 9. This was done as additional function in Matlab: function f=GenerateElementVector(xi,xi1) gi=SourceFct(xi); gi1=SourceFct(xi1); f=[gi*(xi1-xi)/2;gi1*(xi1-xi)/2]; end Assignment 10. This was done as additional function in Matlab: function f=AssembleMatrix(xo,xe,N) S=zeros(N+1,N+1); x=GenerateMesh(xo,xe,N); elmat=GenerateTopology(N); for i=1:N Sei=GenerateElementMatrix(x(i),x(i+1)); for j=1:2 for k=1:2 S(elmat(i,j),elmat(i,k))=S(elmat(i,j),elmat(i,k))+Sei(j,k); end end end f=S; end Assignment 11. This was done as additional function in Matlab: function f=AssembleVector(xo,xe,N) fv=zeros(N+1,1); x=GenerateMesh(xo,xe,N); elmat=GenerateTopology(N); for i=1:N fei=GenerateElementVector(x(i),x(i+1));
  • 5. Sample Assignment For Reference Only for j=1:2 fv(elmat(i,j))=fv(elmat(i,j))+fei(j); end end f=fv; end Assignment 12. This was reached by adding next lines to main program when we calculate the matrix S and vector f before use them to solve en equation : % boundary --- S(1,1)=1; S(1,2)=0; f(1)=0; Assignment 13. We run our main program for N=100 and got the next visualization for S matrix as Assignment 14. Here is the graphs where we have two solutions, analytical u(x) from first part and numerical for N=8, and N=32. N=8 N=32
  • 6. Sample Assignment For Reference Only As we see – for more number of nodes we have better convergence between two solutions, analytical and numerical. Elective Part Part 1 Lets try to write analytical solution as: 1 sin 2 This will give the same result for second derivative as we know that 2 0 So, we after changes in main and additional function we will get the result. As we see the results very unclose – this can be explained that we need change not only analytical solution but also the boundary conditions. Part 2 To compare results for different number of nodes we can write the loop for different N=2,4,8,16,… etc. On every loop we calculate the numerical solution and the error (largest values for mesh).
  • 7. Sample Assignment For Reference Only And we got the next graph for norm of error vs. number of nodes (see q_err.m file): As we see , in logarithmic axes we have linear dependence for logarithm of norm of error from logarithm from number of nodes, this leads from the way we wrote our equations using linear (first order) Lagrangian shape functions. Part 3 Here we changed the program by adding to last element in vector f the value: , 1/ So, in this way we got the next graph with different numerical solutions (for N=16) for different values of α (see q_neumann.m for script): As we see – with increasing of α we get the increasing of left boundary of function