12.07.2015 Views

GNU Octave - Local Sector 7 web page

GNU Octave - Local Sector 7 web page

GNU Octave - Local Sector 7 web page

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

188 <strong>GNU</strong> <strong>Octave</strong>function y = f (x)y = x .* sin (1 ./ x) .* sqrt (abs (1 - x));endfunctionNote the use of the ‘dot’ forms of the operators. This is not necessary for the call toquad, but it makes it much easier to generate a set of points for plotting (because it makesit possible to call the function with a vector argument to produce a vector result).Then we simply call quad:[v, ier, nfun, err] = quad ("f", 0, 3)⇒ 1.9819⇒ 1⇒ 5061⇒ 1.1522e-07Although quad returns a nonzero value for ier, the result is reasonably accurate (to seewhy, examine what happens to the result if you move the lower bound to 0.1, then 0.01,then 0.001, etc.).22.2 Orthogonal Collocation[r, amat, bmat, q] = colloc (n, "left", "right")Loadable FunctionCompute derivative and integral weight matrices for orthogonal collocation usingthe subroutines given in J. Villadsen and M. L. Michelsen, Solution of DifferentialEquation Models by Polynomial Approximation.Here is an example of using colloc to generate weight matrices for solving the secondorder differential equation u ′ −αu ′′ = 0 with the boundary conditions u(0) = 0 and u(1) = 1.First, we can generate the weight matrices for n points (including the endpoints of theinterval), and incorporate the boundary conditions in the right hand side (for a specificvalue of α).n = 7;alpha = 0.1;[r, a, b] = colloc (n-2, "left", "right");at = a(2:n-1,2:n-1);bt = b(2:n-1,2:n-1);rhs = alpha * b(2:n-1,n) - a(2:n-1,n);Then the solution at the roots r isu = [ 0; (at - alpha * bt) \ rhs; 1]⇒ [ 0.00; 0.004; 0.01 0.00; 0.12; 0.62; 1.00 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!