Skip to content

Instantly share code, notes, and snippets.

function [Q, R] = qr(A, econ)
%QR QR factorization of an array-valued CHEBFUN.
% [Q, R] = QR(A) or QR(A, 0), where A is a column CHEBFUN with n columns,
% produces a column CHEBFUN Q with n orthonormal columns and an n x n upper
% triangular matrix R such that A = Q*R.
%
% The algorithm used is described in L.N. Trefethen, "Householder
% triangularization of a quasimatrix", IMA J. Numer. Anal. (30), 887-897
% (2010).
%
% All lengths up to 16, plus an additional 8 random sizes for each power of two larger than that.
coeff_lengths = [
1 2 3 4 5 6 7 8, ...
9 10 11 12 13 14 15 16, ...
17 20 23 25 26 29 30 32, ...
34 37 42 43 49 52 59 64, ...
65 66 67 71 76 89 97 128, ...
129 146 165 171 176 203 233 256, ...
267 276 292 331 378 413 482 512, ...
522 536 709 754 784 909 921 1024, ...
@jrus
jrus / subsref.m
Last active September 16, 2015 06:01
refactoring chebfun/subsref.m
function varargout = subsref(f, index)
%SUBSREF CHEBFUN subsref.
% ( )
% F(X) returns the values of the CHEBFUN F evaluated on the array X. If X
% falls on a breakpoint of F, the corresponding value from F.POINTVALUES is
% returned. F(X, 'left') or F(X, 'right') will evaluate F at breakpoints
% using left- or right-hand limits, respectively. See CHEBFUN/FEVAL for
% further details. F(:) returns F.
%
% If F is an array-valued column CHEBFUN, and X is an array of arbitrary
@jrus
jrus / feval.m
Last active September 15, 2015 09:06
chebfun/feval.m after some refactoring
function out = feval(F, x, varargin)
%FEVAL Evaluate a CHEBFUN.
% FEVAL(F, X) evaluates a CHEBFUN F at the points in X. If F is a quasimatrix
% with columns F1, ..., FN, then the result will be [F1(X), ..., FN(X)], the
% horizontal concatenation of the results of evaluating each column at the
% points in X.
%
% FEVAL(F, 'left'), FEVAL(F, 'start'), and FEVAL(F, '-') return the value of F
% at the left endpoint of its domain. FEVAL(F, 'right'), FEVAL(F, 'end'), and
% FEVAL(F, '+') do the same for the right endpoint.
@jrus
jrus / feval.m
Last active September 11, 2015 08:17
modifications to feval
function out = feval(F, x, varargin)
%FEVAL Evaluate a CHEBFUN.
% FEVAL(F, X) evaluates a CHEBFUN F at the points in X. If F is a quasimatrix
% with columns F1, ..., FN, then the result will be [F1(X), ..., FN(X)], the
% horizontal concatenation of the results of evaluating each column at the
% points in X.
%
% FEVAL(F, 'left'), FEVAL(F, 'start'), and FEVAL(F, '-') return the value of F
% at the left endpoint of its domain. FEVAL(F, 'right'), FEVAL(F, 'end'), and
% FEVAL(F, '+') do the same for the right endpoint.
@jrus
jrus / lua-uuid.lua
Created July 29, 2012 09:26
quick lua implementation of "random" UUID
local random = math.random
local function uuid()
local template ='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
return string.gsub(template, '[xy]', function (c)
local v = (c == 'x') and random(0, 0xf) or random(8, 0xb)
return string.format('%x', v)
end)
end
@jrus
jrus / gist:3113240
Created July 14, 2012 20:32
decode a Mac OS Roman string to a regular Javascript string (code written in coffeescript)
decode_macroman = do ->
high_chars_unicode = '''
ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü
†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø
¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl
‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ
'''.replace /\n/g, ''
(mac_roman_bytestring) ->
char_array = for idx in [0...mac_roman_bytestring.length]
@jrus
jrus / gist:2145082
Created March 21, 2012 06:08
sort a javascript array using a decorate-sort-undecorate pattern; especially useful if the sort comparison is expensive to compute
# Accepts a list and a key function to apply to each item,
# and then uses a decorate-sort-undecorate pattern to actually
# do the sorting. Returns a new list. Keeps track of the index
# to make sure the sort is stable.
sort_by = (list, key) ->
cmp = ({key: k_a, index: i_a}, {key: k_b, index: i_b}) ->
if k_a == k_b then i_a - i_b else if k_a < k_b then -1 else 1
decorated = ({item, index, key: key item} for item, index in list)
item for {item} in decorated.sort cmp