{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

14-440-127 Lecture 12 Notes

14-440-127 Lecture 12 Notes - 14:440:127 Introduction to...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
14:440:127– Introduction to Computers for Engineers Notes for Lecture 12 Rutgers University, Fall 2008 Instructor- Blase E. Ur 1 Symbolic Calculus Recall that last week, we saw numerical methods to estimate the answers to calculus problems. This was useful whenever we had a data set we collected and needed to perform calc operations on that data, or when the function describing the data is fairly complicated. However, if you are dealing with a relatively simple equations, you can use symbolic math, which deals with ”symbols” rather than estimates. For instance, taking the derivative of x 2 would return 2 x rather than an estimate at some particular point. 1.1 Intro to Symbolic Math In general, to tell Matlab that you’re dealing with symbolic numbers, you pass a string to the function sym( ) , which makes that string into a symbolic data type. Once you have symbolic data types, you can perform math operations on them, but the answers will be the exact mathematical symbols rather than estimates, i.e.: >> sym(’2’) * sym(’x^2’) ans = 2*x^2 Notice that rather than looking up what the variable x contains, Matlab here keeps x as a symbol. Alternately, you can specify which ”variables” should be considered symbolic by typing something like syms x y , which will make x and y symbolic variables. From then on, whenever you refer to x or y, Matlab will treat them as a symbol rather than as a variable. >> syms x y >> 2*x^3 ans = 2*x^3 1.2 Making Symbolic Math All Neat and Pretty There are functions like collect , expand , factor , and simplify , among others. You may be able to guess what these do by the names (collect like terms, expand powers, factor an expression, or put the expression into its simplest possible form). For instance, let’s see how collect and factor work:
Image of page 1

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

View Full Document Right Arrow Icon
>> syms x y >> collect(x^2 - 3*x^2 + 5 - 2*x + 32*x) ans = -2*x^2+5+30*x >> factor(x^3-1) ans = (x-1)*(x^2+x+1) You can also solve equations using the solve function: >> syms x y >> solve(’x^2 + 5*x -3 = 11’) ans = 2 -7 If you’ll notice, here I had to put the equation in quotes (because of the equals sign). How do you know when you can just type it normally, have to put it in quotes, or even have to use the sym function? Rather than try to memorize the complex set of rules, try typing it the first way, and then try it the other ways if it gives you an error. One function you might find useful when you’re presenting the output from your curve fitting is poly2sym , which converts a polynomial (stored as a vector) into a symbolic expression. This allows you to display the best fit equation you find as symbols: >> a = 1:3; >> b = a.^2+2*a; >> c = polyfit(a,b,2) c = 1.0000 2.0000 -0.0000 >> poly2sym(c) ans = x^2+2*x-2453841957234431/2535301200456458802993406410752 >> poly2sym(round(c)) ans = x^2+2*x Notice the complication from the fact that Matlab gives you an estimated solution... I decided to round the coefficients to the nearest integer before displaying them so that we don’t show 0 as some ridiculous, small fraction.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern