This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
classdef Dual | |
% DUAL Dual numbers class for automatic differentiation. | |
% | |
% To do automatic differentiation we introduce a number d such that d^2 == 0. | |
% Then by a simple application of Taylor's theorem we have | |
% | |
% f(x + d) = f(x) + f'(x) d | |
% | |
% with all higher-order terms vanishing. Therefore applying a function to a dual | |
% number x + d generates both the value f(x) *and* the derivative f'(x). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function b = isdual(a) | |
%ISDUAL Return true if a is of class Dual, else return false | |
b = strcmp(class(a),'Dual'); | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function SetDefault(argname,value) | |
%SETDEFAULT Provide a default value of VALUE for the argument ARGNAME. | |
% | |
%USAGE | |
% SetDefault('x',1) | |
% If no variable 'x' exists in the calling function, or if the variable exists | |
% but it is empty, then this call assigns the value 1 to 'x'. If the variable | |
% 'x' already exists, and is non-empty, then no action is taken. | |
% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad.ST | |
import Data.STRef | |
-- Primitive actions | |
getSignal wire = wire GetSignal | |
setSignal wire x = wire (SetSignal x) | |
addAction wire proc = wire (AddAction proc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import time | |
N = 200 | |
binsize = 8000; | |
xs = [100 * random.randint(1,40) for i in range(N)] | |
print '\nObjects to be packed:\n' | |
print xs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data NewFloat a = F a deriving (Eq,Ord,Show) | |
instance RealFloat a => Num (NewFloat a) where | |
F x + F y = F (x + y) | |
F x - F y = F (x - y) | |
F x * F y = F (x * y) | |
fromInteger n = F (fromInteger n) | |
abs = newAbs | |
signum = newSignum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- A semi-fast isPrime algorithm | |
noDivs factors n = foldr (\f r -> f*f > n || (rem n f /= 0 && r)) | |
True factors | |
primesTD = 2 : 3 : filter (noDivs $ tail primesTD) [5,7..] | |
isPrime n = n > 1 && noDivs primesTD n | |
divides a b = b `mod` a == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE MultiParamTypeClasses #-} | |
import Data.Maybe | |
import Data.List as List | |
-- Group stuff | |
class Group g where | |
eye :: g | |
(%) :: g -> g -> g |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************************************** | |
* | |
* Customize the values given below to suit your needs. | |
* You can make additional copies of this file with | |
* different customizated settings if you need to load | |
* jsMath with different parameters. | |
* | |
* Load this page via: | |
* | |
* <SCRIPT SRC="path-to-jsMath/easy/load.js"></SCRIPT> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [T Y] = relent(Tspan) | |
%% Configuration | |
leg = {'Species 1','Species 2'}; | |
opts = odeset(); | |
opts.AbsTol = 1e-8; | |
opts.RelTol = 1e-4; |
OlderNewer