variable and plot

8 messages
Open this post in threaded view
|

variable and plot

 Hello, I am starting with octave. 2 questions. 1) If I type this function under octave, it is fine, but when it is in a file and that I make source "myfile.m" I get an error error: 't' undefined near line 1 column 8 function y = f_LG (x, t, wD, g)   tt = t ./ wD;   y = exp (-tt .* tt) ./ ((x .- t).**2 .+ g .* g); endfunction 2) I have a function function y = Voigt (x, wD, g)   y = quad (@(t) w (x, t, wD, g), -10,10); endfunction which seems to work Voigt (0, 5, 0.1) ans =  30.719 but, I cannot plot it x=-10:0.1:10;  plot (x, Voigt (x, 4,0.1)); This gives me a constant value. Thank for your help. ===========================================================================  Patrick DUPRÉ                                 | | email: [hidden email]  Laboratoire de Physico-Chimie de l'Atmosphère | |  Université du Littoral-Côte d'Opale           | |  Tel.  (33)-(0)3 28 23 76 12                   | | Fax: 03 28 65 82 44  189A, avenue Maurice Schumann                 | | 59140 Dunkerque, France ===========================================================================
Open this post in threaded view
|

Re: variable and plot

 On Tue, Apr 10, 2018 at 4:35 AM, Patrick Dupre wrote:Hello, I am starting with octave. 2 questions. 1) If I type this function under octave, it is fine, but when it is in a file and that I make source "myfile.m" I get an error error: 't' undefined near line 1 column 8 function y = f_LG (x, t, wD, g)   tt = t ./ wD;   y = exp (-tt .* tt) ./ ((x .- t).**2 .+ g .* g); endfunction 1)  you should name the file the same name as the function name2) since you didn't then you can do:     q=myfile( xvalues, tvalues, wD value, g value)in other words you must send some numbers to the function  2) I have a function function y = Voigt (x, wD, g)   y = quad (@(t) w (x, t, wD, g), -10,10); endfunction which seems to work Voigt (0, 5, 0.1) ans =  30.719 but, I cannot plot it x=-10:0.1:10;  plot (x, Voigt (x, 4,0.1)); This gives me a constant value. Thank for your help. ===========================================================================  Patrick DUPRÉ                                 | | email: [hidden email]  Laboratoire de Physico-Chimie de l'Atmosphère | |  Université du Littoral-Côte d'Opale           | |  Tel.  (33)-(0)3 28 23 76 12                   | | Fax: 03 28 65 82 44  189A, avenue Maurice Schumann                 | | 59140 Dunkerque, France =========================================================================== -- DAS
Open this post in threaded view
|

Re: variable and plot

 In reply to this post by Patrick Dupre On Tue, Apr 10, 2018 at 4:35 AM, Patrick Dupre wrote:Hello, I am starting with octave. 2 questions. 1) If I type this function under octave, it is fine, but when it is in a file and that I make source "myfile.m" I get an error error: 't' undefined near line 1 column 8 function y = f_LG (x, t, wD, g)   tt = t ./ wD;   y = exp (-tt .* tt) ./ ((x .- t).**2 .+ g .* g); endfunction 2) I have a function function y = Voigt (x, wD, g)   y = quad (@(t) w (x, t, wD, g), -10,10); endfunction It does not work for me. I get Voigt (0, 5, 0.1)error: 'w' undefined near line 2 column 18error: quad: evaluation of user-supplied function failedyou should try "clear all"  and see what happens.Put all functions in a file.  which seems to work Voigt (0, 5, 0.1) ans =  30.719 but, I cannot plot it x=-10:0.1:10;  plot (x, Voigt (x, 4,0.1)); This gives me a constant value. Thank for your help. ===========================================================================  Patrick DUPRÉ                                 | | email: [hidden email]  Laboratoire de Physico-Chimie de l'Atmosphère | |  Université du Littoral-Côte d'Opale           | |  Tel.  (33)-(0)3 28 23 76 12                   | | Fax: 03 28 65 82 44  189A, avenue Maurice Schumann                 | | 59140 Dunkerque, France =========================================================================== -- DAS
Open this post in threaded view
|

Re: variable and plot

 In reply to this post by Patrick Dupre On Tue, Apr 10, 2018, 9:52 AM Patrick Dupre <[hidden email]> wrote:... 2) I have a function function y = Voigt (x, wD, g)   y = quad (@(t) w (x, t, wD, g), -10,10); endfunction which seems to work Voigt (0, 5, 0.1) ans =  30.719 but, I cannot plot it x=-10:0.1:10;  plot (x, Voigt (x, 4,0.1)); This gives me a constant value.You need to understand the outputs of your functions. Run Voigt(x, 4, 0.1) before the plot line and see what your output looks like. quad will only produce a scalar output. So it seems you are calling plot with an array for the x value and a single constant for the y value.
Open this post in threaded view
|

Re: variable and plot

 (please keep the help list in the reply chain) On 4/10/18, Patrick Dupre <[hidden email]> wrote: >> 2) >> I have a function >> function y = Voigt (x, wD, g) >>   y = quad (@(t) w (x, t, wD, g), -10,10); >> endfunction >> >> which seems to work >> >> Voigt (0, 5, 0.1) >> ans =  30.719 >> >> but, I cannot plot it >> >> x=-10:0.1:10; >>  plot (x, Voigt (x, 4,0.1)); >> This gives me a constant value. > > > > You need to understand the outputs of your functions. Run Voigt(x, 4, 0.1) > before the plot line and see what your output looks like. quad will only > produce a scalar output. So it seems you are calling plot with an array for > the x value and a single constant for the y value. > > > I guess that it is the right argument. The question is hwo do I manage the x > vector? > In other words, what is the difference between > x=-10:0.1:10 > plot (x, sin (x)) > and my function? > plot (x, Int_Sat (x, 2, 1, 0.1, 0.01)) > > function y = Int_Sat (x, Shift, wD, g, s) >   y = quad (@(t) Sat (x, t, Shift, wD, g, s), 0, 15) ; > endfunction > > Sin(x) will take a vector input and produce a vector otuput. if Int_Sat does not produce a vector output, then the plot function will not have a vector to work with.  plot is not working with one value of x at a time, it is working with two matrices, but Int_Sat produces a matrix of size (1,1)
Open this post in threaded view
|

Re: variable and plot

 Very good, Then, how can I get a vector in output? By the way, sin(1) works as well as plot (x, sin (x)) How can I obtain the same behavior ? Thank. ===========================================================================  Patrick DUPRÉ                                 | | email: [hidden email]  Laboratoire de Physico-Chimie de l'Atmosphère | |  Université du Littoral-Côte d'Opale           | |  Tel.  (33)-(0)3 28 23 76 12                   | | Fax: 03 28 65 82 44  189A, avenue Maurice Schumann                 | | 59140 Dunkerque, France =========================================================================== > Sent: Tuesday, April 10, 2018 at 6:35 PM > From: "Nicholas Jankowski" <[hidden email]> > To: "Patrick Dupre" <[hidden email]> > Cc: "Help GNU Octave" <[hidden email]> > Subject: Re: variable and plot > > (please keep the help list in the reply chain) > > On 4/10/18, Patrick Dupre <[hidden email]> wrote: > >> 2) > >> I have a function > >> function y = Voigt (x, wD, g) > >>   y = quad (@(t) w (x, t, wD, g), -10,10); > >> endfunction > >> > >> which seems to work > >> > >> Voigt (0, 5, 0.1) > >> ans =  30.719 > >> > >> but, I cannot plot it > >> > >> x=-10:0.1:10; > >>  plot (x, Voigt (x, 4,0.1)); > >> This gives me a constant value. > > > > > > > > You need to understand the outputs of your functions. Run Voigt(x, 4, 0.1) > > before the plot line and see what your output looks like. quad will only > > produce a scalar output. So it seems you are calling plot with an array for > > the x value and a single constant for the y value. > > > > > > I guess that it is the right argument. The question is hwo do I manage the x > > vector? > > In other words, what is the difference between > > x=-10:0.1:10 > > plot (x, sin (x)) > > and my function? > > plot (x, Int_Sat (x, 2, 1, 0.1, 0.01)) > > > > function y = Int_Sat (x, Shift, wD, g, s) > >   y = quad (@(t) Sat (x, t, Shift, wD, g, s), 0, 15) ; > > endfunction > > > > > > > Sin(x) will take a vector input and produce a vector otuput. if > Int_Sat does not produce a vector output, then the plot function will > not have a vector to work with.  plot is not working with one value of > x at a time, it is working with two matrices, but Int_Sat produces a > matrix of size (1,1) >