simple question

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

simple question

Terrence Brannon-13
Why is this screwing up?

function a = apha(V)
     n = -0.01*(V+60)
     d = exp(-(V+60)/10) - 1
     a = n/d
endfunction



octave:1> V=linspace(10,20,100);
octave:2> plot(V,apha(V));
error: __plt2vv__: vector lengths must match
error: evaluating index expression near line 50, column 5
error: evaluating if command near line 49, column 3
error: called from `__plt2vv__' in file `/usr/share/octave/2.0.5/m/plot/__plt2vv__.m'
error: called from `__plt2__' in file `/usr/share/octave/2.0.5/m/plot/__plt2__.m'
error: called from `__plt__' in file `/usr/share/octave/2.0.5/m/plot/__plt__.m'
error: called from `plot' in file `/usr/share/octave/2.0.5/m/plot/plot.m'
octave:2>

--
o============o  Sending unsolicited commercial e-mail (UCE)  to this address
 Legal Notice   is indication of your consent to pay me $120/hour for 1 hour
o============o  minimum for professional proofreading & technical assessment.
  Terrence Brannon * [hidden email] * http://quake.usc.edu/~brannon


Reply | Threaded
Open this post in threaded view
|

simple question

John W. Eaton-6
On 28-Sep-1997, Terrence Brannon <[hidden email]> wrote:

| Why is this screwing up?
|
| function a = apha(V)
|      n = -0.01*(V+60)
|      d = exp(-(V+60)/10) - 1
|      a = n/d
| endfunction
|
|
|
| octave:1> V=linspace(10,20,100);
| octave:2> plot(V,apha(V));
| error: __plt2vv__: vector lengths must match

For a vector argument, your function returns a scalar.  I think you
really want to write

  function a = apha(V)
    n = -0.01*(V+60)
    d = exp(-(V+60)/10) - 1
    a = n ./ d                # really want element-by-element operator here?
  endfunction

jwe


efh
Reply | Threaded
Open this post in threaded view
|

Re: simple question

efh
In reply to this post by Terrence Brannon-13
( Re: Message from Terrence Brannon )

>
> Why is this screwing up?
>
> function a = apha(V)
>      n = -0.01*(V+60)
>      d = exp(-(V+60)/10) - 1
>      a = n/d
> endfunction
>
> octave:1> V=linspace(10,20,100);
> octave:2> plot(V,apha(V));
> error: __plt2vv__: vector lengths must match

Because:
  octave-2:1> function a = apha(V)
  > n = -0.01*(V+60);
  > d = exp(-(V+60)/10) - 1;
  > a = n/d;
  > endfunction
  octave-2:2> V=linspace(10,20,100);
  octave-2:3> a=apha(V);
  octave-2:4> size(a)
  ans =

    1  1

  octave-2:5>

However, if you replace the "a = n/d" with "a = n./d" (component-by-
component division) you should get what I guess you want:
  octave-2:5> function a = apha(V)
  > n = -0.01*(V+60);
  > d = exp(-(V+60)/10) - 1;
  > a = n./d;
  > endfunction
  octave-2:6> V=linspace(10,20,100);
  octave-2:7>  plot(V,apha(V));
  octave-2:8>
which produced a plot OK (looked like a remarkably good approximation to
a straight line to me ... ).

Cheers,
Ted.                                    ([hidden email])