0
votes

I have a function

function f=ejer3(a,x)
    f=1/(1+exp(a*x))
endfunction

Now I want to plot this function for three values of a (a=0.5,1,2) and 100 values of x between -4 and 4. That is to say, I want to plot three functions f1, f2, f3; each one is plotted using one value of a and the 100 values of x.

For example:

x=linspace(-4,4)
f1=1/(1+exp(0.5*x))

And plotting f1.

How do I do this? Do I have to use a for loop? I'm new in scilab.

1

1 Answers

1
votes

In your case the simpler and most efficient solution is to write a vectorized version of ejer3:

function f=ejer3(a,x)
    a=a(:);//column vector
    x=matrix(x,1,-1);// row vector
    f=1.0./(1+exp(a*x))
endfunction

and then

 a=[0.5,1,2];
 x=linspace(-4,4,100);
 ejer3(a,x)

If the function cannot be vectorized one can use the feval function.