Lecture S2 Symbolic Math Using MATLAB: Part 2 - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Lecture S2 Symbolic Math Using MATLAB: Part 2

Description:

Simultaneous non-linear equations. Selection of one of several or solutions ... Solution of simultaneous linear equations. Solve 2x-3y 4z=5, y 4z x=10, -2z 3x ... – PowerPoint PPT presentation

Number of Views:80
Avg rating:3.0/5.0
Slides: 11
Provided by: williamr150
Category:

less

Transcript and Presenter's Notes

Title: Lecture S2 Symbolic Math Using MATLAB: Part 2


1
Lecture S2Symbolic Math Using MATLAB Part 2
  • Solution of equations
  • Symbolic solution of single equations
  • Simultaneous linear equations
  • Simultaneous non-linear equations
  • Selection of one of several or ? solutions
  • Creation of symbolic Taylor series

2
Solution of symbolic equations
  • Find the two solutions to the classic quadratic
    equation, ax2 bx c 0. What is the first
    step?
  • syms a b c x
  • Step 2 Define the equation eq'ax2bxc0'
  • Step 3 Solve the equation x solve(eq,x)
  • Step 4 If more than one solution, pull out the
    one you want. In this case, how would you select
    the first?
  • x x(1) What do you get?
  • Step 5 If desired, substitute desired values for
    variables, e.g. a 3, b 1, c 10. What
    command?
  • subs(x,a,b,c,3,1,10)
  • ans -0.1667 1.8181i

3
  • Find the solution to e2x3y. Do step 1
  • clear, syms x y Do step 2
  • eq 'exp(2x) 3y' Do step 3
  • xsolve(eq,x) x
    1/2log(3y)
  • Is this natural log or log base 10?
  • Now, just for fun, ezplot(x)
  • What are the two axes?

4
Solution of simultaneous linear equations
  • Solve 2x-3y4z5, y4zx10, -2z3x4y0 step 1?
  • clear, syms x y z step 2?
  • eq1'2x-3y4z5', eq2'y4zx10',
    eq3'-2z3x4y0' step 3?
  • x,y,zsolve(eq1,eq2,eq3,x,y,z)
  • x -5/37, y 45/37, z 165/74
  • Note while the symbols in the equations can be
    in any order (unlike MATLAB's numerical methods),
    the results are given in alphabetical order so
    you must be careful what you put inside the
    brackets.
  • How do you convert to floating point numeric
    format?
  • xdouble(x), ydouble(y), zdouble(z)

5
Selection of one of infinite solutions
  • How many solutions are there for sin(x)1/2?
  • What does the solve command give?
  • clear, syms x, eq'sin(x)1/2', xsolve(eq,x)
    gives x pi/6 (0.5236)
  • Suppose you want the solution for x between 2 and
    3. See gtgt mhelp fsolve (the mhelp indicates that
    fsolve is in the Maple kernel and so is not
    available in the student version). Unusual
    syntax
  • clear, xmaple('fsolve(sin(x)1/2,x,2..3)') x
    2.6179938779914943653855361527329
  • whos, 2x

6
How to use solution for further calc'ns? x
str2double(x), y2x, whos
7
(No Transcript)
8
Taylor series
  • Uses differentials to generate a polynomial
    approximation to an expression about a point.
  • Syntax taylor(expression,order,variable,point)
  • Example Expand ex about x 0 to order 5.
  • clear, syms x, Tay_expxtaylor(exp(x),5,x,0)
    1x1/2x21/6x31/24x4
  • Compare at x 2 with the exact value.
  • approxsubs(Tay_expx,x,2), exactexp(2),
    frac_errabs(1-approx/exact)
  • approx 7, exact 7.38905609893065, frac_err
    0.05265301734371
  • Graph Taylor and exact on same using ezplot

9
ezplot(Tay_expx), hold on, ezplot(exp(x)), hold
off
Which one's the Taylor approximation, red or blue?
10
Test yourself
  • Solve the following equations simultaneously
    for x and y axbyx23 cxby0
  • Select the second solution and set a1, b2, c3.
  • What are these as double type variables?
  • Find the fifth order Taylor series approximation
    for sin2(x)e-x about x?.
  • What is the percent error of this approximation
    at x 1.1 ??
Write a Comment
User Comments (0)
About PowerShow.com