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 00:46:58 +0100

On Sun, Feb 16, 2014 at 11:57 PM, Erik Leunissen <address@hidden> wrote:

I have no concrete solution to your particular problem, mainly cause I
can't test your function. If you provide working code, people will be
able to try things faster and come up with solutions.

I have a couple of suggestions
> function C = myfunc (x,t)
>         global M A v Dx k;
>         C=M/A*exp(-(x-v*t)^2/(4*Dx*t)-k*t)/(2*sqrt(pi*Dx*t));
> endfunction
>
> In another file "parameters.m", I've got default values for the variables M,
> A, v Dx and k.
>
Unless for some real crazy reason you need globals here, I would try
not to use them, for example you could do
function C = myfunc (x,t,M=0, A=1, v=10, Dx=0.1, k=-1)
C=M/A*exp(-(x-v*t)^2/(4*Dx*t)-k*t)/(2*sqrt(pi*Dx*t));
endfunction

to put your default values, or you can pack them all in one nice
structure which is also probably easier to understand.

> In octave at the command line, I first check whether the function myfunc
> works:
>
> octave:1> source parameters.m
> octave:2> myfunc(2,3)
> ans =  5.2180

You do not need to call source script.m just call the sript
octave:1> parameters


reply via email to

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