miércoles, 20 de junio de 2012

Using the MATLAB PDE TOOLBOX



http://www.indiana.edu/~statmath/math/matlab/pde/index.html

Using the MATLAB PDE TOOLBOX

by David Hart
The MATLAB PDE Toolbox is a tool for solving two-dimensional linear partial differential equations by finite element methods. This document is intended to guide you through the use of the graphical user interface for interactive use. It assumes that the reader is running MATLAB and the PDE toolbox in a graphical environment.
At the MATLAB prompt, type pdetool. You should see a window like the one below pop up.
PDEtool screenshot
We will work through the solution of Laplace's equation with Dirichlet boundary conditions. Solutions of Laplace's equation, called harmonic functions, describe situations in which forces are balanced, as might occur in electrostatics or thermal equilibria. This is an example which might be first encountered in an elementary PDE course, and which you might solve by Fourier series methods, by hand; you will find that you obtain the solution faster with the PDE Toolbox, and that you also obtain a visual representation, which may contribute to the more important goal of understanding. We will then modify the example, to one which might not be so easily done by hand.
  1. Draw the region of interest: suppose we want the rectangle (x,y) = [0, 3] X [0, 1].
    • In the Options menu, select Grid and Snap; then set the Axes' Limits to [-1 4] and [-1 2]. When finished, click Apply and Close the Axes' Limits window.
PDEtool screenshot
    • In the Draw menu, select Rectangle/Square (not centered).
    • In the drawing region, click and hold with the cursor at the origin, and drag it to the point with coordinates (3,1). The region will be shaded and marked R1.
PDEtool screenshot
  1. Set up the boundary conditions: suppose we want the unknown solution function u to be -1 on the long horizontal sides, and +1 on the short vertical sides.
    • In the Boundary menu, select Boundary Mode. The window changes to this:
PDEtool screenshot
    • In the drawing region, double click on the left edge of the rectangle. The boundary condition window pops up. The default Dirichlet condition h*u=r is OK, the default h=1 is OK; change the value of r to +1.
PDEtool screenshot
    • Do the same thing with the right edge: double-click, set the value. On the top and bottom edges, set r to -1. Be patient and careful. When the boundary conditions are correctly set, you should be able to click on any edge, and see the correct value for r.
  1. Specify the particular PDE of interest:
    • In the PDE menu, select PDE specification. The pde specification window pops up; we are doing the default type of problem, elliptic, of the form -div(c*grad(u)) + a*u = f, where a=0, f=0, and c=1. Change the values as needed, and click on OK.
PDEtool screenshot
  1. Generate the mesh:
    • In the Mesh menu, select Initialize Mesh. This time we will use the default mesh.
PDEtool screenshot
  1. Solve the Finite Element problem:
    • In the Solve menu, select Solve PDE. The figure in the main drawing area changes.
PDEtool screenshot
  1. Generate other plots:
    • In the Plot menu, select Parameters. The plot parameter window pops up; click on the check boxes for color, contour, and height, then on the Plot button.
PDEtool screenshot
A new figure window pops up, with the appropriate plot.
PDEtool screenshot
Click the Done button [the height plot will remain the default].
The contours are pretty jagged, you may wish to get a better result. Go back to the Mesh menu, and select Refine mesh; Solve again; if you wish, repeat the process. You can click and hold with the left mouse button, and then drag to change the viewing angle.
PDEtool screenshot
Let's solve a similar problem: Laplace's equation on the same rectangle, with different boundary conditions.
  1. Go back to Boundary mode.
    • Make the boundary conditions on the short vertical sides be 4*sin(pi*y).^2 .
PDEtool screenshot
On the long horizontal sides make it -.05 * x.^4 .* (3 - x).^2 on the bottom, -.05*x.^2.*(3 - x).^4 on the top.
PDEtool screenshot
  1. Then solve and plot, again. This time we have set the plot parameters to color and contour, but not height:
PDEtool screenshot
In the figure below, we have again checked the height box in the Plot Parameters window, and under Property, we have made the color vary with abs(grad(u)). You can click on the figure window and drag to obtain a different point of view.
PDEtool screenshot
You may want to save your work; click on File, then Save As... Save your session in your own directory, as pdeintro.m. Then you can quit MATLAB, and at some later time restart it and enter pdeintro at the MATLAB command prompt to return to the current state.
The PDE Toolbox can be used from the command prompt without using the GUI interface illustrated above, or in batch mode using m-files. For example, several demonstration files are included with the package; at the MATLAB command prompt, type pdedemo1 [alternatively, pdedemos brings up a menu window].
The code may be examined, in the $MATLAB/toolbox/pde directory.
The MATLAB PDE Toolbox is a product of Computer Solutions Europe AB.

Matlab Con Metodos Numericos

 
Prefacio
En estas notas ofrecemos una variedad de temas del análisis numérico,que pueden servir de motivación y de guía a estudiantes de nuestraUniversidad y a otros interesados. Se pueden considerar como unasnotas de clase, pero, para la selección de temas y enfoques, no se siguióun programa de curso dado.Los más de 100 ejercicios están repartidos en pequeñas listas enmedio de la exposición, ejercicios suplementarios y exámenes de en-trenamiento. Hay cerca de 30 ejemplos resueltos en detalle, que casisiempreaparecen con surutina MATLABacompañante. Dichasrutinasse presentan únicamente con …nes didácticos y no sustituyen softwarede calidad.Pretendemospublicar estasnotas en la WEB y mantenerlas enevolu-ción. Por eso los aportes de usuarios son muy importantes. Comenta-rios, correcciones y sugerencias son bienvenidos en la dirección electró-nica
cemejia@ perseus:unalmed:edu:co:
Expresamos nuestro reconocimiento a la Universidad Nacional deColombia, por habernos concedido el año sabático durante el cual es-cribimos estas notas.Parte de este documento se utilizará como guía en un cursillo dela XIII Escuela Latinoamericana de Matemáticas, que se reunirá enCartagena, Colombia de julio 29 a agosto 3 de 2002.Medellín, julio 15 de 2002


Matlab Con Metodos Numericos

Curso de EDPs PDE Ecuaciones en Derivadas Parciales

 http://math.tut.fi/~piche/pde/

MAT-51316
Partial Differential Equations
spring 2011

Teacher

prof. Robert Piché

Schedule

Lectures

no lectures. The recorded lectures from last year (listed below) can be used for self-study.

Exercises

Tuesdays 2-4pm in Td308. No teaching Jan 25.

Midterm exam

Tuesday March 8 2011 in Td308

Contents

The course covers the fundamental linear PDEs (transport, Laplace, diffusion, and wave equation), how they arise as mathematical models of physical phenomena, analytical tools (Fourier series, maximum principles, Duhamel's principle, Green's functions, etc), and numerical solution methods.

Study Materials

Course notes

1. PDE models, transport equation, method of characteristics  slides, recording, exercises, solutions
2. One-dimensional models of vibration, diffusion and heat conduction slides, recording, exercises, solutions
3. Wave equation: d'Alembert's formula, energy analysis slides, recording, exercises, solutions
4. Diffusion initial-value problem  slides, recording, exercises, solutions
5. Waves and Diffusion on half-line, Duhamel's principle  slides, recording, exercises, solutions
6.  Separation of Variables slides, recording, exercises, solutions
7. Solving one-dimensional problems with Matlab-PDEPE exercises, solutions
8. Fourier series slides, recording, exercises, solutions
9. Laplace's equation slides, recording, exercises, solutions
10. Solving Laplace's equation slides, recording, exercises, solutions
11. Green's functions slides, recording, exercises, solutions
12. Matlab PDE toolbox (demo)

vanhoja tentteja / old exams: 11.2008, 1.2009, 2.2010
vanhoja välikokeita / ole midterm exams: 1.2010


päivitetty / updated 18.1.2011 by RP


Líneas de Transmisión, Guías de ondas y líneas de transmisión


Líneas de Transmisión, Guías de ondas y líneas de transmisión
Una guía de ondas es un dispositivo que se usa para transportar energía electromagnética y/oinformación de un sitio a otro. Generalmente se usa el término línea de transmisión a la guía deondas usada en el extremo de menor frecuencia del espectro.
A estas frecuencias es posible utilizar un análisis cuasiestático. Para frecuencias más elevadas la aproximación cuasiestáticadeja de ser válida y se requiere un análisis en términos de campos, que es de mayor complejidad.Veremos este tratamiento en el Capítulo 9.Podemos pensar a una línea de transmisión básicacomo un par de electrodos que se extienden paralelos por una longitud grande (en relación con la longitudde onda) en una dada dirección. El par de electrodosse hallan cargados con distribuciones de carga (varia- bles a lo largo de la línea) iguales y opuestas, for-mando un capacitor distribuido. Al mismo tiempocirculan corrientes opuestas (variables a lo largo de lalínea) de igual magnitud, creando campo magnéticoque puede expresarse a través de una inductanciadistribuida. La potencia fluye a lo largo de la línea.Los ejemplos más importantes de líneas de transmi-sión son el par bifilar, el coaxil y la microcinta.


Líneas de Transmisión

Solución de Ecuaciones en Derivadas PArciales con Matlab pdepe

 http://www.mathworks.com/help/techdoc/ref/pdepe.html

pdepe - Solve initial-boundary value problems for parabolic-elliptic PDEs in 1-D

Syntax

sol = pdepe(m,pdefun,icfun,bcfun,xmesh,tspan)
sol = pdepe(m,pdefun,icfun,bcfun,xmesh,tspan,options)
[sol,tsol,sole,te,ie] = pdepe(m,pdefun,icfun,bcfun,xmesh,tspan,options)

Arguments

mA parameter corresponding to the symmetry of the problem. m can be slab = 0, cylindrical = 1, or spherical = 2.
pdefunA handle to a function that defines the components of the PDE.
icfunA handle to a function that defines the initial conditions.
bcfunA handle to a function that defines the boundary conditions.
xmeshA vector [x0, x1, ..., xn] specifying the points at which a numerical solution is requested for every value in tspan. The elements of xmesh must satisfy x0 < x1 < ... < xn. The length of xmesh must be >= 3.
tspanA vector [t0, t1, ..., tf] specifying the points at which a solution is requested for every value in xmesh. The elements of tspan must satisfy t0 < t1 < ... < tf. The length of tspan must be >= 3.
optionsSome options of the underlying ODE solver are available in pdepe: RelTol, AbsTol, NormControl, InitialStep, MaxStep, and Events. In most cases, default values for these options provide satisfactory solutions. See odeset for details.

Description

sol = pdepe(m,pdefun,icfun,bcfun,xmesh,tspan) solves initial-boundary value problems for systems of parabolic and elliptic PDEs in the one space variable x and time t. pdefun, icfun, and bcfun are function handles. See Function Handles in the MATLAB Programming documentation for more information. The ordinary differential equations (ODEs) resulting from discretization in space are integrated to obtain approximate solutions at times specified in tspan. The pdepe function returns values of the solution on a mesh provided in xmesh.
Parameterizing Functions, in the MATLAB Mathematics documentation, explains how to provide additional parameters to the functions pdefun, icfun, or bcfun, if necessary.
pdepe solves PDEs of the form:
(2-2)
The PDEs hold for t0 ≤ t ≤ tf and a ≤ x ≤ b. The interval [a,b] must be finite. m can be 0, 1, or 2, corresponding to slab, cylindrical, or spherical symmetry, respectively. If m > 0, then a must be ≥ 0.
In Equation 2-2, f (x,t,u,∂u/∂x) is a flux term and s (x,t,u,∂u/∂x) is a source term. The coupling of the partial derivatives with respect to time is restricted to multiplication by a diagonal matrix c (x,t,u,∂u/∂x). The diagonal elements of this matrix are either identically zero or positive. An element that is identically zero corresponds to an elliptic equation and otherwise to a parabolic equation. There must be at least one parabolic equation. An element of c that corresponds to a parabolic equation can vanish at isolated values of x if those values of x are mesh points. Discontinuities in c and/or s due to material interfaces are permitted provided that a mesh point is placed at each interface.
For t = t0 and all x, the solution components satisfy initial conditions of the form
(2-3)
For all t and either x = a or x = b, the solution components satisfy a boundary condition of the form
(2-4)
Elements of q are either identically zero or never zero. Note that the boundary conditions are expressed in terms of the flux f rather than ∂u/∂x. Also, of the two coefficients, only p can depend on u.
In the call sol = pdepe(m,pdefun,icfun,bcfun,xmesh,tspan):
  • m corresponds to m.
  • xmesh(1) and xmesh(end) correspond to a and b.
  • tspan(1) and tspan(end) correspond to t0 and tf.
  • pdefun computes the terms c, f, and s (Equation 2-2). It has the form
    [c,f,s] = pdefun(x,t,u,dudx)
    
    The input arguments are scalars x and t and vectors u and dudx that approximate the solution u and its partial derivative with respect to x, respectively. c, f, and s are column vectors. c stores the diagonal elements of the matrix c (Equation 2-2).
  • icfun evaluates the initial conditions. It has the form
    u = icfun(x)
    
    When called with an argument x, icfun evaluates and returns the initial values of the solution components at x in the column vector u.
  • bcfun evaluates the terms p and q of the boundary conditions (Equation 2-4). It has the form
    [pl,ql,pr,qr] = bcfun(xl,ul,xr,ur,t)
    
    ul is the approximate solution at the left boundary xl = a and ur is the approximate solution at the right boundary xr = b. pl and ql are column vectors corresponding to p and q evaluated at xl, similarly pr and qr correspond to xr. When m > 0 and a = 0, boundedness of the solution near x = 0 requires that the flux f vanish at a = 0. pdepe imposes this boundary condition automatically and it ignores values returned in pl and ql.
pdepe returns the solution as a multidimensional array sol. ui = ui = sol(:,:,i) is an approximation to the ith component of the solution vector u. The element ui(j,k) = sol(j,k,i) approximates ui at (t,x) = (tspan(j),xmesh(k)).
ui = sol(j,:,i) approximates component i of the solution at time tspan(j) and mesh points xmesh(:). Use pdeval to compute the approximation and its partial derivative ∂ui/∂x at points not included in xmesh. See pdeval for details.
sol = pdepe(m,pdefun,icfun,bcfun,xmesh,tspan,options) solves as above with default integration parameters replaced by values in options, an argument created with the odeset function. Only some of the options of the underlying ODE solver are available in pdepe: RelTol, AbsTol, NormControl, InitialStep, and MaxStep. The defaults obtained by leaving off the input argument options will generally be satisfactory. See odeset for details.
[sol,tsol,sole,te,ie] = pdepe(m,pdefun,icfun,bcfun,xmesh,tspan,options) with the 'Events' property in options set to a function handle Events, solves as above while also finding where event functions g(t,u(x,t))are zero. For each function you specify whether the integration is to terminate at a zero and whether the direction of the zero crossing matters. Three column vectors are returned by events: [value,isterminal,direction] = events(m,t,xmesh,umesh). xmesh contains the spatial mesh and umesh is the solution at the mesh points. Use pdeval to evaluate the solution between mesh points. For the I-th event function, value(i) is the value of the function, ISTERMINAL(I) = 1 if the integration is to terminate at a zero of this event function and 0 otherwise. direction(i) = 0 if all zeros are to be computed (the default), +1 if only zeros where the event function is increasing, and -1 if only zeros where the event function is decreasing. Output tsol is a column vector of times specified in tspan, prior to first terminal event. SOL(j,:,:) is the solution at T(j). TE is a vector of times at which events occur. SOLE(j,:,:) is the solution at TE(j) and indices in vector IE specify which event occurred.
If UI = SOL(j,:,i) approximates component i of the solution at time TSPAN(j) and mesh points XMESH, pdeval evaluates the approximation and its partial derivative ∂ui/∂x at the array of points XOUT and returns them in UOUT and DUOUTDX: [UOUT,DUOUTDX] = PDEVAL(M,XMESH,UI,XOUT)
    Note   The partial derivative ∂ui/∂x is evaluated here rather than the flux. The flux is continuous, but at a material interface the partial derivative may have a jump.

Tips

  • The arrays xmesh and tspan play different roles in pdepe.
    tspan – The pdepe function performs the time integration with an ODE solver that selects both the time step and formula dynamically. The elements of tspan merely specify where you want answers and the cost depends weakly on the length of tspan.
    xmesh – Second order approximations to the solution are made on the mesh specified in xmesh. Generally, it is best to use closely spaced mesh points where the solution changes rapidly. pdepe does not select the mesh in x automatically. You must provide an appropriate fixed mesh in xmesh. The cost depends strongly on the length of xmesh. When m > 0, it is not necessary to use a fine mesh near x = 0 to account for the coordinate singularity.
  • The time integration is done with ode15s. pdepe exploits the capabilities of ode15s for solving the differential-algebraic equations that arise when Equation 2-2 contains elliptic equations, and for handling Jacobians with a specified sparsity pattern.
  • After discretization, elliptic equations give rise to algebraic equations. If the elements of the initial conditions vector that correspond to elliptic equations are not "consistent" with the discretization, pdepe tries to adjust them before beginning the time integration. For this reason, the solution returned for the initial time may have a discretization error comparable to that at any other time. If the mesh is sufficiently fine, pdepe can find consistent initial conditions close to the given ones. If pdepe displays a message that it has difficulty finding consistent initial conditions, try refining the mesh.
    No adjustment is necessary for elements of the initial conditions vector that correspond to parabolic equations.

Examples

Example 1. This example illustrates the straightforward formulation, computation, and plotting of the solution of a single PDE.
This equation holds on an interval 0 ≤ x ≤ 1 for times t ≥ 0.
The PDE satisfies the initial condition
and boundary conditions
It is convenient to use subfunctions to place all the functions required by pdepe in a single function.
function pdex1

m = 0;
x = linspace(0,1,20);
t = linspace(0,2,5);

sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
% Extract the first solution component as u.
u = sol(:,:,1);

% A surface plot is often a good way to study a solution.
surf(x,t,u) 
title('Numerical solution computed with 20 mesh points.')
xlabel('Distance x')
ylabel('Time t')

% A solution profile can also be illuminating.
figure
plot(x,u(end,:))
title('Solution at t = 2')
xlabel('Distance x')
ylabel('u(x,2)')
% --------------------------------------------------------------
function [c,f,s] = pdex1pde(x,t,u,DuDx)
c = pi^2;
f = DuDx;
s = 0;
% --------------------------------------------------------------
function u0 = pdex1ic(x)
u0 = sin(pi*x);
% --------------------------------------------------------------
function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)
pl = ul;
ql = 0;
pr = pi * exp(-t);
qr = 1;
In this example, the PDE, initial condition, and boundary conditions are coded in subfunctions pdex1pde, pdex1ic, and pdex1bc.
The surface plot shows the behavior of the solution.

The following plot shows the solution profile at the final value of t (i.e., t = 2).

Example 2. This example illustrates the solution of a system of PDEs. The problem has boundary layers at both ends of the interval. The solution changes rapidly for small t.
The PDEs are
where F(y) = exp(5.73y) – exp(–11.46y).
This equation holds on an interval 0 ≤ x ≤ 1 for times t ≥ 0.
The PDE satisfies the initial conditions
and boundary conditions
In the form expected by pdepe, the equations are
The boundary conditions on the partial derivatives of u have to be written in terms of the flux. In the form expected by pdepe, the left boundary condition is
and the right boundary condition is
The solution changes rapidly for small t. The program selects the step size in time to resolve this sharp change, but to see this behavior in the plots, the example must select the output times accordingly. There are boundary layers in the solution at both ends of [0,1], so the example places mesh points near 0 and 1 to resolve these sharp changes. Often some experimentation is needed to select a mesh that reveals the behavior of the solution.
function pdex4
m = 0;
x = [0 0.005 0.01 0.05 0.1 0.2 0.5 0.7 0.9 0.95 0.99 0.995 1];
t = [0 0.005 0.01 0.05 0.1 0.5 1 1.5 2];

sol = pdepe(m,@pdex4pde,@pdex4ic,@pdex4bc,x,t);
u1 = sol(:,:,1);
u2 = sol(:,:,2);

figure
surf(x,t,u1)
title('u1(x,t)')
xlabel('Distance x')
ylabel('Time t')

figure
surf(x,t,u2)
title('u2(x,t)')
xlabel('Distance x')
ylabel('Time t')
% --------------------------------------------------------------
function [c,f,s] = pdex4pde(x,t,u,DuDx)
c = [1; 1]; 
f = [0.024; 0.17] .* DuDx; 
y = u(1) - u(2);
F = exp(5.73*y)-exp(-11.47*y);
s = [-F; F]; 
% --------------------------------------------------------------
function u0 = pdex4ic(x);
u0 = [1; 0]; 
% --------------------------------------------------------------
function [pl,ql,pr,qr] = pdex4bc(xl,ul,xr,ur,t)
pl = [0; ul(2)]; 
ql = [1; 0]; 
pr = [ur(1)-1; 0]; 
qr = [0; 1]; 
In this example, the PDEs, initial conditions, and boundary conditions are coded in subfunctions pdex4pde, pdex4ic, and pdex4bc.
The surface plots show the behavior of the solution components.


References

[1] Skeel, R. D. and M. Berzins, "A Method for the Spatial Discretization of Parabolic Equations in One Space Variable," SIAM Journal on Scientific and Statistical Computing, Vol. 11, 1990, pp.1–32.

See Also

function_handle | ode15s | odeget | odeset | pdeval

lunes, 18 de junio de 2012

scorpions - lonely nights

scorpions - lonely nights

Since you're gone
There is an empty space
Since you're gone
The world is not the same

I go back to the places we've been
It feels like you're still there
I live all those moments again
Wishing you were here

Since you're gone
There is an lonely heart
Since you're gone
Nothin' is like it was

There are memories all over the place
Bringin' it back all so clear
Remember all of those days
Wishing you were here

All those lonely nights
I gotta fight for you, yes I do
Yes I do

Since you're gone
There is a heart that bleeds
Since you're gone
I'm not the man I used to be

I follow you steps in the snow
The traces disappear
We know what we've lost when it's gone
I'm wishing you were here

All those lonely nights
I gotta fight for you, yes I do
Yes I do

Gun's N' Roses - Knockin On Heavens Door

Mama take this badge from me
I can't use it anymore
It's getting dark too dark to see
Feels like I'm knockin' on heaven's door

Knock-knock-knockin' on heaven's door
Knock-knock-knockin' on heaven's door
Knock-knock-knockin' on heaven's door
Knock-knock-knockin' on heaven's door

Mama put my guns in the ground
I can't shoot them anymore
That cold black cloud is comin' down
Feels like I'm knockin' on heaven's door

Knock-knock-knockin' on heaven's door
Knock-knock-knockin' on heaven's door
Knock-knock-knockin' on heaven's door
Knock-knock-knockin' on heaven's door

"You just better start sniffin' your own
rank subjugation jack 'cause it's just you
against your tattered libido, the bank and
the mortician, forever man and it wouldn't
be luck if you could get out of life alive"*
Knock-knock-knockin' on heaven's door