Laplace transform with example

Embed Size (px)

Citation preview

MathematicaMathematica

Mathematica 8.0.0 GNU/Linux frontend Developer(s) Wolfram Research Initial release June 23, 1988[1] Stable release 8.0.4 (October 24, 2011) [] Preview release [] Written in Mathematica, C Platform Cross-platform (list) Available in English, Chinese and Japanese. Computer algebra, numerical computations, Information Type visualization, statistics, user interface creation License Proprietary Website www.wolfram.com/mathematica/ Mathematica is a computational software program used in scientific, engineering, and mathematical fields and other areas of technical computing. It was conceived by Stephen Wolfram and is developed by Wolfram Research of Champaign, Illinois.[2][3] The name of the program Mathematica was suggested to Stephen Wolfram by Apple co-founder Steve Jobs although Stephen Wolfram had thought about it earlier and rejected it.[4]

[edit]Features

Dini's surface plotted with adjustable parameters

Features of Mathematica include:[5] Elementary mathematical function library Special mathematical function library Matrix and data manipulation tools including support for sparse arrays Support for complex number, arbitrary precision, interval arithmetic and symbolic computation 2D and 3D data and function visualization and animation tools Solvers for systems of equations, diophantine equations, ODEs, PDEs, DAEs, DDEs and recurrence relations Numeric and symbolic tools for discrete and continuous calculus Multivariate statistics libraries including fitting, hypothesis testing, and probability and expectation calculations on over 100 distributions. Constrained and unconstrained local and global optimization Programming language supporting procedural, functional and object oriented constructs Toolkit for adding user interfaces to calculations and applications Tools for image processing[6] and morphological image processing including image recognition Tools for visualizing and analysing graphs

Tools for combinatoric problems Tools for text mining including regular expressions and semantic analysis Data mining tools such as cluster analysis, sequence alignment and pattern matching Number theory function library Tools for financial calculations including bonds, annuities, derivatives, options etc. Group theory functions Libraries for wavelet analysis on sounds, images and data Control systems libraries Continuous and discrete integral transforms Import and export filters for data, images, video, sound, CAD, GIS,[7] document and biomedical formats Database collection for mathematical, scientific, and socio-economic information and access to WolframAlpha data and computations Technical word processing including formula editing and automated report generating Tools for connecting to DLLs. SQL, Java, .NET, C+ +, FORTRAN, CUDA, OpenCL and http based systems Tools for parallel programing Using both "free-form linguistic input" (a natural language user interface) [8] and Mathematica language in notebook when connected to the Internet

[edit]InterfaceMathematica is split into two parts, the kernel and the front end. The kernel interprets expressions (Mathematica code) and returns result expressions. The front end, designed by Theodore Gray, provides a GUI, which allows the creation and editing of Notebook documents containing program code with prettyprinting, formatted text together with results including typeset mathematics, graphics, GUI components, tables, and sounds. All contents and formatting can be generated algorithmically or interactively edited. Most standard word processing capabilities are supported, but there is only one level of "undo." Documents can be structured using a hierarchy of cells, which allow for outlining and sectioning of a document and support automatic numbering index creation. Documents can be presented in a slideshow environment for presentations. Notebooks and their contents are represented as Mathematica expressions that can be created, modified or analysed by Mathematica programs. This allows conversion to other formats such asTeX or XML. The front end includes development tools such as a debugger, input completion and automatic syntax coloring. The standard front end is used by default, but alternative front ends are available. They include the Wolfram Workbench, an Eclipse based IDE, introduced in 2006. It provides project-based code development tools for Mathematica, including revision management, debugging, profiling, and testing. [9] Mathematica also includes a command line front end.[10]

[edit]High-performance computingIn recent years, the capabilities for high-performance computing have been extended with the introduction of packed arrays (version 4, 1999)[11] and sparse

matrices (version 5, 2003),[12] and by adopting theGNU Multi-Precision Library to evaluate high-precision arithmetic. Version 5.2 (2005) added automatic multi-threading when computations are performed on multi-core computers.[13] This release included CPU specific optimized libraries. In addition Mathematica is supported by third party specialist acceleration hardware such as ClearSpeed.[14] In 2002, gridMathematica was introduced to allow user level parallel programming on heterogeneous clusters and multiprocessor systems [15] and in 2008 parallel computing technology was included in all Mathematica licenses including support for grid technology such as Windows HPC Server 2008, Microsoft Compute Cluster Server and Sun Grid. Support for CUDA and OpenCL GPU hardware was added in 2010. Also, version 8 can generate C code, which is automatically compiled by a system C compiler, such as Intel C++ Compiler or compiler ofVisual Studio 2010.

[edit]DevelopmentSeveral solutions are available for deploying applications written in Mathematica: Mathematica Player Pro is a runtime version of Mathematica that will run any Mathematica application but does not allow editing or creation of the code.[16] A free-of-charge version, Wolfram CDF Player, is provided for running Mathematica programs that have been saved in the Computable Document Format (CDF).[17] It can also view standard Mathematica files, but not run them. It includes plugins for common web browsers. webMathematica allows a web browser to act as a front end to a remote Mathematica server. It is designed to allow a user written application to be remotely accessed via a browser on any platform. It may not be used to give full access to Mathematica. Mathematica code can be converted to C code or to an automatically generated DLL.

[edit]Connections with other applicationsCommunication with other applications occurs through a protocol called MathLink. It allows communication between the Mathematica kernel and front-end, and also provides a general interface between the kernel and other applications. Although Mathematica has a large array of functionality, a number of interfaces to other software have been developed, for use where other programs have functionality that Mathematica does not provide, to enhance those applications, or to access legacy code. Wolfram Research freely distributes a developer kit for linking applications written in the C programming language to the Mathematica kernel through MathLink.[18] Using .NET/Link.,[19] a .NET program can ask Mathematica to perform computations; likewise, a Mathematica program can load .NET classes, manipulate .NET objects and perform method calls. This makes it possible to build .NET graphical user interfaces from within Mathematica. Similar functionality is achieved with J/Link.,[20] but with Java programs instead of .NET programs.

Communication with SQL databases is achieved through built-in support for JDBC.[21] Mathematica can also install web services from a WSDL description. [22][23] Other languages that connect to Mathematica include Haskell,[24] AppleScript, [25] Racket,[26] Visual Basic,[27] Python[28][29] and Clojure.[30] JavaTools[31] is a Java-based solution for Mathematica that provides several high-performance implementations of various algorithms, mostly combinatorial optimization and concurrency, as well as instant compilation and execution of user code in Java, Scala, C#, and F#. Links are available to many specialized mathematical software packages including OpenOffice.org Calc,[32] Microsoft Excel,[33] MATLAB,[34][35] R,[36] [37] Sage,[38][39] SINGULAR,[40] Wolfram SystemModelerand Origin.[41] Mathematical equations can be exchanged with other computational or typesetting software via MathML. Mathematica can capture real-time data via a link to LabView,[42] from financial data feeds[43] and directly from hardware devices via GPIB (IEEE 488), [44] USB[45] and serial interfaces.[46] It automatically detects and reads from HID devices. Alternative interfaces are available such as JMath,[47] based on GNU readline and MASH[48] which runs self contained Mathematica programs (with arguments) from the UNIX command line.

[edit]Computable data

A stream plot of live weather data

Mathematica includes collections of curated data in a consistent framework for immediate computation. Data can be accessed programmatically to inform or test models and is updated automatically from a data server at Wolfram Research.[49] Some data such as share prices and weather are delivered in realtime. Data sets currently include: Astronomical data: 99 properties of 155,000 astronomical bodies Chemical data: 111 properties of 34,000 chemical compounds, 86 properties of 118 chemical elements and 35 properties of 1000 subatomic particles Geopolitical data: 225 properties of 237 countries and 14 properties of 160,000 cities around the world Financial data: 71 historical and real-time properties of 186,000 shares and financial instruments

Mathematical data: 89 properties of 187 polyhedra, 258 properties of 3000 graphs, 63 properties of 6 knots, 37 properties of 21 lattice structures, 32 properties of 52 geodesic schemes Language data: 37 properties of 149,000 English words. 26 additional language dictionaries Biomedical data: 41 properties of all 40,000 human genes, 30 properties of 27,000 proteins Weather data: live and historical measurements of 43 properties of 17,000 weather stations around the world Wolfram|Alpha data: trillions of data points from WolframAlpha

Mathematica: The Laplace Transform

IntroductionOn this page, I hope to show you how to use Mathematica to perform the Laplace Transform and the Inverse Laplace Transform ; moreover, by the end, I hope you will be able to solve a second order differential equations using these methods. To run Mathematica, proceed as directed on the previous tutorial. Do not forget to set the DISPLAY variable as directed there! The main new commands we will be using here are called LaplaceTransform andInverseLaplaceTransform. However, if you run Mathematica and try to get help on one of them, say by typing ? LaplaceTransform, you should get a message saying that the symbol was not found. This is because the LaplaceTransform is not a default Mathematica command. In order to teach Mathematica about the Laplace Transform, we have to tell it to read the system folder in which the relevant commands are defined. So, issue the following command each time you start Mathematica and plan to use the LaplaceTransform:In[1] := = 0, we can define a new function (of s), called the Laplace Transform of f, as

We can use Mathematica to evaluate this integral for many relevant choices of f. The command is defined with the following syntax: LaplaceTransform[f[t],t,s]. Some easy examples Here are some simple examples to try:LaplaceTransform[Sin[a t],t,s] LaplaceTransform[t^2,t,s] LaplaceTransform[t^3,t,s] LaplaceTransform[a t^2 + b t^3,t,s]

Easy enough. A tricky example Here is an example which involves the Laplace Transform, but thanks to a mathematical fact, can be reduced to simply evaluating an integral. The purpose of introducing you to this example is primarily to illustrate some new ways of thinking when using Mathematica and to teach you some new commands. Let's get started: Suppose the function f(t) is periodic of period P. By this, I mean that the f(t)=f(t+P), for all real numbers t. Then it can be shown that the Laplace Transform is equal to

Now, let us use Mathematica to find the Laplace Transform of f(t), which we define to be f(t)=1-t if 0 {Automatic,{0,.5,1,1.5}}]

NOTE that before beginning Mathematica you should have set the DISPLAY variable as was discussed in the other tutorials!! If you don't, then you will not see any graphics output.

Now, using the above equation with P=1 and f(t)=1-t, we can arrive at the Laplace Transform through the following sequence of commands:In[7] := stepone = Integrate[(1-t)Exp[-s t],{t,0,1}] In[8] := lf = 1/(1-Exp[-s]) stepone//Simplify

In line 7, we evaluated the integral using Mathematica and called the answer stepone. In line 8, we combined two Mathematica commands into one line by using the double slash (//) notation : first stepone was multiplied by the term which appears in front of the integral, then second, we Simplify'd the expression to get the final answer, namely lf.

Inverse Laplace TransformSuppose we would like to find the inverse Laplace transform of 1/(8+4s+s^2). We can use Mathematica by issuing the following command:In[10] := InverseLaplaceTransform[1/(8+4s+s^2),s,t]

To avoid having to retype InverseLaplaceTransform every time you want to perform the inverse transform, I suggest creating an alias, such as ILT by simply performing the assignmentIn[11] := ILT = InverseLaplaceTransform

within Mathematica. Now, we can proceed as before but without having to do as much typing. Nice!In[12] := ILT[1/(8+4s+s^2),s,t]

Note: You do not have to use ILT as your alias. Feel free to use whatever you want ; I will continue to use ILT throughout the remainder of this handout. Some easy examples Let's try some easy example:ILT[1/s^2,s,t] ILT[s/(s^2+4),s,t] ILT[a s/(s^2+4) - b/(s^2-4),s,t]

Getting Tricky Let's again get a little tricky. Suppose we would like to compute the inverse Laplace Transform of

1/(s^n (s*s+16)), for n=0,1,2,3,4,5,6. A good exercise for you is to show that if F(n) denotes the inverse Laplace transform for 1/(s^n(s*s+16)), then one can compute the F(n+1) by the following formula:

Thus we can set up a recursion relation in Mathematica as follows:In[13] := Clear[F] In[14] := F[0] = ILT[1/(s^2+16),s,t] In[15] := F[n_] := F[n] = Integrate[F[n-1] /. t->a, {a,0,t}]

We end this exercise by printing out the results in table form:In[16] := Table[{n,F[n]},{n,0,6}]//TableForm

Notice again here that we used the double-slash notation to take the output of the first command and use it as input to the second command, TableForm.

Solving second order equationsFinally, let's use Mathematica to solve a differential equations via the Laplace Transform. For the first problem, let's solve y''+2y'+4y=t-exp(-t), subject to y(0)=1 and y'(0)=1.In[17] := lhsone=LaplaceTransform[y''[t]+2y'[t]+4y[t],t,s]

After taking the Laplace Transform of the differential equation, we can plug in the initial values and make a substitution for the Transform of y (usually denoted capital Y, which, remember, is still unknown) ; we do this with the following command:In[18] := lhstwo = lhsone /. {LaplaceTransform[y[t],t,s]->capy,y[0]->1,y'[0]->1}

Now we compute the transform of the right hand side:In[19] := rhs=LaplaceTransform[t-Exp[-t],t,s]

and solve for capital y.In[20] := stepthree=Solve[lhstwo==rhs,capy]

Now we must extract the solution from all of the surrounding brakets with the following command:In[21] := stepfour=stepthree[[1,1,2]]

so we can then compute the inverse transform and find the solution to our problem!

In[22] := sol=ILT[stepfour,s,t]

The above six steps can be used as a general recipe for solving differential equations using the Laplace Transform, provided Mathematica knows the transform of the left annd right hand side. In some cases, you may have to do some of the work on your own, "by hand", before proceeding. A step function example Let us consider the same example above, but with a different right hand side. In particular, we will use the step function which is equal to one when x is greater than 5 and zero when x is less than 5. This function is known as u_5 in your textbook. We can define a function like this in Mathematica with the commandf[x_] := If[x-1} rhs=LaplaceTransform[UnitStep[t-5],t,s] stepthree=Solve[lhstwo==rhs,capy] stepfour=stepthree[[1,1,2]] sol=ILT[stepfour,s,t] Plot[sol,{t,-1,15}]

and there you have it. With this information, you should be able to easily solve a lot of homework-type problems just by using Mathematica!