lab3 - Lab 3: Matlab and the Maple Kernel Background Both...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Page 1 of 7 Lab 3: Matlab and the Maple Kernel Background Both Maple and Matlab can be very useful in exploring the concepts of this course and in checking your homework problems. The good news is that the Maple kernel can be accessed from inside Matlab. We will show how this works below. Begin by opening Matlab. Example1 – Calculations and Display Precision in Matlab. a. Multiple statements in Matlab can be entered on the same line. Separate the statements by commas as shown below. Notice assignment in Matlab simply used the equals sign whereas Maple uses := instead. If you do not assign the result of a calculation to a named variable, Matlab places the result in the variable ans by default. Thus ans is the analog of % in Maple. > sqrt(3), cos(pi), c = sqrt( 3^2 + 4^2) ans = 1.73205080756888 ans = -1 c = 5 Unlike Maple, notice Matlab represents an exact expression like 3 by a decimal approximation whereas Maple would treat 3 exactly. b. Evaluate π to the maximum precision in Matlab. The constant π is built into Matlab and will be needed especially when we compute Fourier series. Enter π as pi in Matlab. Note this is different than Maple where π is entered as Pi . > pi; gives 3.1416 if the default display is set to short. Unfortunately, this displays π to only five digits if the default display format is set to short . To change to the long format use the format command shown below. > format long, pi, single (pi) gives ans = 3.14159265358979 ans = 3.1415927 Changing the format to long does not effect the calculational precision of Matlab, only how it displays the results. The long format displays 15 digits for double and 7 digits for single precision variables. c. Matlab is case sensitive. If you by mistake use the Maple notation for π as Pi you get the following error message. > Pi gives ??? Undefined function or variable 'Pi'. Example 2: Accessing the Maple Kernel a. Suppose we wish to evaluate π to 50 digits inside Matlab. At first this sounds impossible as Matlab does not directly support arbitrary precision arithmetic unlike Maple where the number of digits allowed is unlimited. Fortunately, it is possible to perform arbitrary precision calculations in Matlab via the Maple Kernel which it contains. You can access Maple's commands and constants such as Pi within Matlab by using the keyword maple . Simply place any valid Maple command within single quotes as shown below. Use the maple statement to access the Maple Kernel from Inside Matlab. Just place your actual Maple commands between single quotes as shown. > maple( ' Actual Maple Statements ' ) > r = maple('evalf(Pi, 50)') gives r = 3.1415926535897932384626433832795028841971693993751 But note that the result although it looks like a number is not in fact a number. You can see this by attempting to add 1 to r. > r + 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/22/2009 for the course ECES 302 taught by Professor Carr during the Spring '08 term at Drexel.

Page1 / 7

lab3 - Lab 3: Matlab and the Maple Kernel Background Both...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online