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

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

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 Yields a strange looking result. To see that r is an array, and not a number as it would be in Maple, let's ask for its size using the size command.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern