help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: creating a plot of a self-defined function


From: Juan Pablo Carbajal
Subject: Re: creating a plot of a self-defined function
Date: Mon, 17 Feb 2014 11:35:03 +0100

On Mon, Feb 17, 2014 at 10:47 AM, Erik Leunissen <address@hidden> wrote:
> function C = myfunc (x, t, M=100.0 , A=1.0, v=1.0, Dx=2.0, k=1.0)
>         C=M/A*exp(-(x-v*t)^2/(4*Dx*t)-k*t)/(2*sqrt(pi*Dx*t));
> endfunction

Ok, the problem is the following: You are asking octave to divide by
the matrix t. Since t can't be inverted, octave warns you that the
condition number of the inverse ("rcond") is below machine precision
(the inverse has a 0 singular value, i.e. not inverted). Ok, but where
did you ask for a matrix division?
Well, ezmesh internally makes a mesh of the arguments of the functions
and then it passes them to your function. If you change your function
defintion to

function C = myfunc (x, t, M=100.0 , A=1.0, v=1.0, Dx=2.0, k=1.0)
 S = Dx*t;
 C = M/A * exp ( -(x-v*t).^2 ./ (4*S) - k*t ) ./ (2*sqrt(pi*S) );
endfunction
You will get no warning and the plot will be produced.
Note the "./" and the ".^" opertors. This are element-wise operators.
It allows the caller to evaluate on matrix input arguments as if they
were a collection of different input pairs.

Note that you can achieve the same plot by using meshgrid, i.e.
[X Y] = meshgrid (linspace (-5,10,20), linspace (0,10,20) );
Z = myfunc (X, Y);
mesh (Z)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]