02 Matlab and Roots I

8990 xfzerof4findrootinvicinityof4 x 68990

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: also an array. >> x = roots([a b c]) % values in square brackets creates an array x = ‐6.8990 2.8990 >> p = [a b c]; >> x = roots(p); >> x(1) % x(1) is the firstelement of the result ans = ‐6.8990 >> x(2) ans = 2.8990 Points to remember: • [v1 v2 v3 …. Vn] is a array • Array indices start at 1 (not at zero as in C++) • A(n) selects the nth element of array A 4 1/10/2013 Matlab Function “fzero” Function fzero is a general root finding function. In order to use it the function of interest must be defined: >> f = @(x) a*x^2 + b*x + c; fzero must be given either a range of interest or a ballpark value >> x = fzero(f, [0 4]) % find root between 0 and 4 x = 2.8990 >> x = fzero...
View Full Document

Ask a homework question - tutors are online