Create function

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

Create function

rizal
Hai All
 I created the function like this. I call the function but  have errors

function f = perm(n,x);
    f = exp(n(1)*tanh((x+n(2))/n(3)))+n(4);
end

c = [1 -5 5 0];
d = 26.578;

aa = perm(c,d)

this is the error message
error: 'n' undefined near line 3 column 13
error: called from
    test-function at line 3 column 7
error: evaluating argument list element number 1
error: called from
    test-function at line 3 column 7

Thank you very much

best regards
rizal

--
LEMBAGA PENERBANGAN DAN ANTARIKSA NASIONAL (LAPAN)
DEPUTY BIDANG SAINS PENGKAJIAN DAN INFORMASI KEDIRGANTARAAN
PUSAT PEMANFAATAN SAINS ANTARIKSA
JL. DR DJUNDJUNAN NO 133 BANDUNG

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Create function

karl
Am 29.11.2017 um 06:29 schrieb Rizal suryana:
>
> function f = perm(n,x);
>     f = exp(n(1)*tanh((x+n(2))/n(3)))+n(4);
> end
>
> c = [1 -5 5 0];
> d = 26.578;
>
> aa = perm(c,d)
Works for me:

 >> function f = perm(n,x);
     f = exp(n(1)*tanh((x+n(2))/n(3)))+n(4);
end
 >>
 >> c = [1 -5 5 0];
 >> d = 26.578;
 >>
 >> aa = perm(c,d)
aa =  2.7173


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Create function

mmuetzel
In reply to this post by rizal
If you save that code into one single file and want to execute that, you have
to indicate that it should be run as a script. This can be done by simply
adding a line with "1;" before your function definition. Otherwise, Octave
will try to execute your file as a function and will be missing its input
arguments. Hence the error you are seeing.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave