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: Erik Leunissen
Subject: Re: creating a plot of a self-defined function
Date: Mon, 17 Feb 2014 10:47:38 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0

On 02/17/2014 12:46 AM, Juan Pablo Carbajal wrote:> 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.
>

Thanks for your suggestions. Using these, I've rearranged things a bit to provide the following code for testing:

In a function file "myfunc.m", I have now:

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

Then, at the command line, I do:

octave:1> myfunc(2,3)
ans =  0.54997
octave:2> C = @(x,t) myfunc (x,t);
octave:3> ezmesh (C, [-5, 10, 0, 10]);
warning: matrix singular to machine precision, rcond = 0
warning: matrix singular to machine precision, rcond = 0
octave:4>

Like before, the resulting plot window doesn't hold a plot, just the empty grid.

Note aside: since the function myfunc now accepts additional parameters beyond x and t, I'm unsure whether the values in the second parameter provided to the ezmesh command ([-5, 10, 0, 10]), match up correctly with the x and t arguments.

Best regards,

Erik Leunissen
--



> 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]