Git Product home page Git Product logo

examples's Introduction

About

Chebfun is an open-source software system for numerical computing with functions. The mathematical basis of Chebfun is piecewise polynomial interpolation implemented with what we call “Chebyshev technology”. The foundations are described, with Chebfun examples, in the book Approximation Theory and Approximation Practice. Chebfun has extensive capabilities for dealing with linear and nonlinear differential and integral operators, and it also includes continuous analogues of linear algebra notions like QR and singular value decomposition. The Chebfun2 extension works with functions of two variables defined on a rectangle in the x-y plane. To get a sense of the breadth and power of Chebfun, a great place to start is by looking at our Examples.

Installation and requirements

Chebfun is compatible with MATLAB 7.8 (R2009a) and later.

To install, you can either clone the directory with Git or download a .zip file. Note that a call to clear classes is required if you had a previous version of Chebfun installed.

Option 1: Download .zip file

Download a .zip of Chebfun from

After unzipping, you will need to add Chebfun to the MATLAB path. You can do this either (a) by typing

addpath(chebfunroot), savepath

where chebfunroot is the path to the unzipped directory, (b) by selecting the chebfun directory with the pathtool command, or (c) though the File > Set Path... dialog from the MATLAB menubar.

Option 2: Clone with Git

To clone the Chebfun repository, first navigate in a terminal to where you want the repository cloned, then type

git clone https://github.com/chebfun/chebfun.git

To use Chebfun in MATLAB, you will need to add the chebfun directory to the MATLAB path as above.

Getting started

We recommend taking a look at the Chebfun Guide and the Examples collection. The Guide is an in-depth tour of Chebfun's mathematical capabilities. The Examples, which number well over one hundred, illustrate everything from rootfinding to optimization to nonlinear differential equations and vector calculus. Many users use the Examples as templates for their own problems.

To get a taste of what computing with Chebfun is like, type

x = chebfun('x');

and start playing. The variable x is a chebfun and can be manipulated in a way that feels symbolic, although everything Chebfun does is numeric. So try, for instance:

f = sin(12*x).*exp(-x);         % A function on [-1, 1]
g = max(f, 1./(x+2));           % The max of f and 1./(x+2)
plot(g)                         % A function with discontinuous derivative
sum(g)                          % The integral of g
plot(diff(g))                   % The derivative of g
h = g + x - .8;                 % A function with several roots in [-1, 1]
rr = roots(h);                  % Compute the roots of h
plot(h, 'k', rr, h(rr), 'ro')   % Plot h and its roots

License

See LICENSE.txt for Chebfun's licensing information.

examples's People

Contributors

aaustin141 avatar abigopal avatar ajt60gaibb avatar asgeirbirkis avatar bhashemi avatar goretkin avatar gradywright avatar hadrien-montanelli avatar heatherw3521 avatar kuanxu avatar mhsnjvd avatar mikaelslevinsky avatar nakatsukasayuji avatar nboulle avatar nickhale avatar oliviersete avatar rothos avatar stinch avatar tobydriscoll avatar trefethen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

examples's Issues

SolidHarmonics.m

I think this line https://github.com/chebfun/examples/blob/master/sphere/SolidHarmonics.m#L112 was supposed to be the definition of alm. Also, blm has an n, presumably supposed to be l.

Also, the stated complexity https://github.com/chebfun/examples/blob/master/sphere/SolidHarmonics.m#L89, O(l log l), of constructing a regular solid harmonic Rlm as a ballfun should be O(l^2) as determined by the loop https://github.com/chebfun/chebfun/blob/master/%40ballfun/solharm.m#L112 over the O(l) evaluation points https://github.com/chebfun/chebfun/blob/master/%40ballfun/solharm.m#L89, dominating over the additional cost of the FFT.

Actually, this is one application where the algorithm sketched out in chebfun/chebfun#2320 is not only more accurate, being backward stable, but also carries a lower complexity since it would cost only O(lm + l log^2 l): the first part comes from the nested loop of Givens rotations and the second part from the cost of Chebfun's fast polynomial transforms, such as leg2cheb. When m = o(l), this approach should be faster for you.

`FundamentalTheoremOfAlgebra` needs attention

Alex, would you take a look at this example? It runs, but no longer gives output that matches the text. Hrothgar, this isn't ready for the new web site until Alex gives the all-clear.

ode/PiecewiseDemo example needs updating

The intent of the ode/PiecewiseDemo example is to give the user a peak at what's going on under the "cheb-hood". As v5 is an entirely new model, this example needs to be re-written to illustrate the v5 "cheb-hood" features.

Unclear legends in plots

Looking at the ODE-EIG examples, I found many of them had very illegible legends. In particular, http://chebfun.github.io/examples/ode-eig/WaveDecay.html , looks bad, and there are some other around.

As a quick fix, I'd suggest the sizes of the plots to be increased, or at least the font size.

More generally, I don't think that the font shown on the plots in the examples is the most beautiful one. It is easy to get nice looking fonts on Matlab plots via adding (..., 'interpreter', 'latex') to the title() and x/ylabel() commands, and it can be done for legends as well, although a big more involved,

hl = legend('My line')
hl = set(hl, 'interpreter', 'latex')

Scalable vector graphics in examples

To keep tickets focused, I didn't want to include this in the previous issue.

Another thing that strikes me when going through the examples is that the font has started to look very nicely for text and math equations, however, the plots leave something to be desired. In particular, their not scalable, which would be a nice feature to have, so that one could zoom into them while keeping the resolution.

A way for dealing with this might be to use the FileExchange package found at http://www.mathworks.co.uk/matlabcentral/fileexchange/7401-scalable-vector-graphics--svg--export-of-figures .

surface plots look bad

Currenlty, to generate figures for the Examples and Guide, ı am using a command like

export_fig('-painters', '-transparent', figureName)

where export_fig is the popular function from File Exchange (also now on Github!). Most of the figures look great this way, but surface plots are rendered with a strange texture. For example, here’s a figure from Chapter 12 of the Guide:

image

Referencing Examples

I would like to reference an Example in a paper, but the URLs are not stable enough for this. (For example, which recently split ode into ode-linear and ode-nonlinear.)

Does anyone have any suggestions as to how we could improve this? Presumably it's something we would like people to do?

Linewidth 1.6

I notice in some examples (e.g. http://chebfun.github.io/examples/ode/Carrier.html), that we specify the linewidth to be 1.6. Does this actually have any effect? To my eyes, the lines below prove that's not the case:

>> subplot(1,3,1), plot(sin(4*pi*x),'linewidth', 1), title('LW = 1')
>> subplot(1,3,2), plot(sin(4*pi*x),'linewidth', 1.6), title('LW = 1.6')
>> subplot(1,3,3), plot(sin(4*pi*x),'linewidth', 2), title('LW = 2'), shg

I'm attaching the output with this issue. I suggest that we move from 1.6 to 2.
linewidths

ChebfunAD needs to be updated for v5 syntax

The ode/ChebfunAD example fails when doing:

x = chebfun('x');
u = sin(x);
ujac = u.jacobian

The .jacobian field does not appear to be supported in v5. I believe there is a different way to do this in v5 after a brief discussion with @asgeirbirkis.

PDE15S examples

As far as I can tell there are no examples which show how pde15s() and/or pde23t() can be used.

Even if it's just copying one of the exported chebgui demos and adding some more text, that would be useful.

Figures in Spherefun Examples

The figures in the Spherefun examples on the web are quite blurry. Can this be easily fixed?

More specifically:

  1. One can barely make out that the arrows in the quiver plots in http://www.chebfun.org/examples/sphere/HelmholtzDecomposition.html
  2. The images in
    http://www.chebfun.org/examples/sphere/SphereHeatConduction.html
    seem very low quality.

If this could be fixed somehow, then @gradywright and I would be very pleased. I assume there is a parameter in an internal PHP script somewhere that is drastically compressing these images before uploading them to the Chebfun web folder. These figures appear fine when I do my own MATLAB publish and view in a web browser.

linalg/FieldOfValues fails

Error using cellfun
Non-scalar in Uniform output, at index 7, output 1.
Set 'UniformOutput' to false.
Error in chebfun/plot (line 162)
jumpLineIsSet = any(cellfun(@(v) strcmpi(v, 'JumpLine'), varargin));
Error in FieldOfValues (line 60)
hold off, plot(real(FB),imag(FB),'b',LW,lw,'jumpline',{'b',LW,lw})

How to push changes

I made several changes to the ODE examples to update the syntax for chebop in v5. I now want to push these changes to the examples repository. When I type
git push origin master
I get the error:
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Can someone help me figure out what this means and how to fix it?

complex/PhasePortraits breaks now

In particular, the line

g = chebfun2(@(z) sum(z.^(0:9)),[-1 1 -1 1]*pi/2,'vectorise');

gives the error

Error using .^
Matrix dimensions must agree.
Error in @(z)sum(z.^(0:9))

Error in chebfun2/constructor>@(x,y)op(x+1i*y) (line 97)
    op = @(x, y) op( x + 1i*y );
Error in chebfun2/sampleTest (line 22)
vOp = feval(op, xeval, yeval);
Error in chebfun2/constructor (line 307)
        pass = g.sampleTest(op, tol);
Error in chebfun2 (line 57)
            f = constructor(f, varargin{:});

I've tried tweaking the line with no luck. Insight, @ajt60gaibb ?

Undefined function or variable 'chebfun'. Error Message

i got

Undefined function or variable 'chebfun'. Error Message.

line 26
dom = [-1 1 -1 1]; x = chebfun('x',dom(1:2)); tspan = [0 3500];

it seems he defined a function named chebfun somewhere but having read through your code, i can't find the function chebfun.
am i missing anything?

One-dimensional constrained optimization looks weird on website

My apologies if issues with how examples are displayed on the new website don't belong on this tracker, but in any case, I wanted to mention that there are issues with the LaTeX rendering of:
http://chebfun.github.io/examples/opt/ConstrainedOptimization.html ,

both in the first section and in the second sections.

Also, that example makes use of the method inPolygon(), stating that it may be added to a future version of Chebfun. Is the plan to do so for v5?

stats/CentralLimitTheorem breaks now

Error using mapping/inv
Too many input arguments.
Error in deltafun/changeMap (line 20)
f.deltaLoc = newMapping.for(oldMapping.inv(f.deltaLoc));
Error in deltafun/conv (line 86)
            hij = deltaMagF(i, j) * changeMap(diff(g,i-1), deltaLocF(j) + [c d]);
Error in chebfun/conv (line 82)
        hjk = conv(f.funs{j}, g.funs{k});  
Error in CentralLimitTheorem (line 106)
p2 = conv(p1,p1);

replace `rand('seed', 1)` with `rng(1)`

Some examples still use the legacy pseudorandom number generator, which can cause problems if several examples are run in succession.

>> rand('seed', 1)
>> rng(1)
Error using rng (line 96)
The current random number generator is the legacy generator.  This is because
you have executed a command such as rand('state',0), which activates MATLAB's
legacy random number behavior.  You may not use RNG to reseed the legacy random
number generator.

Use rng('default') to reinitialize the random number generator to its startup
configuration, or call RNG using a specific generator type, such as
rng(seed,'twister').

ı propose that all examples use rng.

BVPSystem needs to be updated or possibly removed

Quasimatrix support in chebop is no longer an option. This means that the second part of the BVPSystem example (Section 3) is obsolete. There is a ticket on the chebfun tracker (277) to add support in chebop for chebmatrices. If this is implemented then the second part of BVPSystem should be updated with this new syntax.

Five out of six ode-eig examples fail

I suspect solutions are returned as chebmatrices now rather than chebfuns? Or something like that.

ode-eig/DoubleWell:

Undefined function 'mrdivide' for input arguments of type 'chebmatrix'.
Error in DoubleWell (line 47)
  v = EV(:,j)/15; d = D(j,j);

ode-eig/Drum:

Error using subsref
Subscript indices must either be real positive integers or logicals.
Error in chebmatrix/subsref (line 20)
        varargout{1} = chebmatrix(subsref(A.blocks, sr1));
Error in Drum (line 42)
V = V*diag(sign(V(0,:)));  % ensure V(0,k) > 0

ode-eig/Eigenstates:

Undefined function 'cheb2cell' for input arguments of type 'chebmatrix'.
Error in chebfun/quantumstates (line 113)
W = cheb2cell(W);
Error in Eigenstates (line 40)
quantumstates(V)

ode-eig/SolarQDA:

Error using semilogy
Conversion to double from chebmatrix is not possible.
Error in SolarQDA (line 75)
semilogy(Psi.^2,LW,lw), ylabel('probability'),

ode-eig/WaveDecay:

Undefined function 'mrdivide' for input arguments of type 'chebmatrix'.
Error in WaveDecay (line 22)
  v = v/norm(v,inf);          % normalize to have amplitude 1

orbiting electrons example (`ode-nonlin/TwoElectrons`) throws error

I tried running the code from http://www.chebfun.org/examples/ode-nonlin/TwoElectrons.html but it gets stuck:

LW = 'linewidth'; MS = 'markersize'; lw = 1.2;
chebfunpref.setDefaults('splitting',true)
N = chebop(0,40);
N.op = @(t,z) diff(z,2) + 2*z./abs(z).^3 - 0.25i*imag(z)./imag(z).^3;
V = 1; N.lbc = [1i; V];
tic, z = N\0; x = real(z); y = imag(z);
plot(0,0,'.k',MS,8), hold on
plot(x,y,x,-y,LW,lw), axis(1.2*[-1 1 -1 1]), axis square, hold off
set(gca,'xtick',-1:1,'ytick',-1:1)

Throws an error when it gets to z = N\0:

Undefined function 'imag' for input arguments of type 'treeVar'.

Error in chebop.vectorizeOp/@(t,z)diff(z,2)+2.*z./abs(z).^3-0.25i.*imag(z)./imag(z).^3

Error in treeVar.toFirstOrder (line 58)
    fevalResult = funIn(t, args{:});

Error in chebop/solveivp (line 124)
    [anonFun, varIndex, problemDom, coeffs, diffOrders] = ...

Error in  \  (line 49)
    [varargout{1:nargout}] = solveivp(N, rhs, pref, varargin{:});

Running on Matlab 2014a on a Mac. Chebfun v5.4.0.

MarchingSquares has a bug

Alex, the final computation of roots/MarchingSquares produces a plot that I think is wrong. Can you fix and update this example and push the result? Then I will do one further editing pass before asking @Hrothgar to install it at the new web site.

quantum states does not "feel" the dirac delta function

While using quantumstates along with the potential V=dirac(x), it seems that the energies eigenstates computed by quantumstates are exactly the same as that of V=0. This remains the same for several delta functions, located at different positions. It seems that the delta function potential is 'invisible' to quantumstates. Any ideas on how to fix this? (assuming I want to use the dirac(x) function MATLAB offers, and not write an ad hoc delta potential myself)

ode-nonlin/BVPSystem is broken

Example ode-nonlin/BVPSystem gives the error message

Warning: Rank deficient, rank = 0, tol =  0.000000e+00. 
> In chebop.solvebvpNonlinear at 100
  In chebop.solvebvp at 177
  In BVPSystem at 29 
Warning: Rank deficient, rank = 0, tol =  0.000000e+00. 
> In chebop.solvebvpNonlinear at 100
  In chebop.solvebvp at 177
  In BVPSystem at 65 

@asgeirbirkis, can you sort this out?

reminder to reinclude ModellingDiseases in nightly tests

The example ode-nonlin/ModellingDiseases has been excluded from the nightly tests until the IVP branch is merged into Chebfun’s development branch. This issue is a reminder to test that example again once the IVP branch is merged.

plotting issues in several examples

The following examples have recently-introduced graphics issues due to the various v5 plotting bugs. In theory the examples do not need to be changed — they just need to be rerun once the bugs in Chebfun are fixed.

  • approx/WeierstrassFunction — ylim issue possible related to 'interval' flag
  • calc/DeltaDerivs — ylim issue pertaining to deltafuns
  • geom/Lissajous — flag 'color' doesn’t work on final plot
  • geom/Ellipses — ellipse has a kink in it for some reason
  • linalg/LevelRepulsion — ylim issues
  • ode/LorenzAttractor — ylim issues
  • ode-eig/SolarQDA — ylim issues
  • approx/OrthPolys — ylim issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.