02 Matlab and Roots I

x 67 x 67

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: expression after the command prompt causes Matlab to output the value of the expression. >> 1+1 ans = 2 >> 2^3 ans = 8 >> 2*3+4 ans = 10 >> 2*(3+4) ans = 14 Points to remember: ^ is exponentiation The usual rules of precedence apply 2 1/10/2013 Assigning to a name creates a memory (variable) and gives it a value. >> x = 67 x= 67 Output can be suppressed by ending commands with a semi‐colon. >> y = 50; In general spaces don’t matter, but there is one exception... >> y/2 ans = 25 >> y / 2 ans = 25 >> y /2 ??? Error: "y" was previously used as a variable, conflicting with its use here as the name of a function or command. Point to remember: The space issue can’t arise in assignments. Our Problem In Matlab >> a = 1; >> b = 4; >> c = -20; >> disc = b^2 - 4 * a * c; >> x1 = (-b + sqrt(disc)) / (2 * a) x1 = 2.8990 % no semi-colon to see result >> x2 = (-b - sqrt(disc)) / (2 * a) x2 = -6.8990 For our problem the root that matters (the one with physical meaning) is clearly 2.8990. Point to remember: ‘%’ starts a comment (except within strings) 3 1/10/2013 Some Matlab Basi...
View Full Document

This note was uploaded on 03/30/2013 for the course ECOR 2606 taught by Professor Goheen during the Spring '10 term at Carleton CA.

Ask a homework question - tutors are online