Question:
what is wrong with my scilab function?
?
2010-12-23 15:37:20 UTC
i haven't used scilab before but i have used matlab and i heard it is supposed to be similar. i tried to make a practice function

function out=myfun(in)
guess=1;
for i=1:100
guess=0.5*(guess+(in/guess))
end
out=guess;
endfunction

when i try to run it on the command window i get

-->myfun(4)
!--error 4
Undefined variable: myfun
Three answers:
anonymous
2010-12-23 16:56:05 UTC
You have to explicitly load your function in the current workspace. Do that at the beginning of your main (calling) file. Matlab doesn't need that and it's one important difference.



You can load your function from within the editor window.

Execute > Load into Scilab



or use getf('function.extension') before you run your code. If necessary, include your whole path.
Steven B
2010-12-23 15:56:24 UTC
3.2 Variable name

Variable names may be as long as the user wants, but only the rst 24 characters are taken into

account in Scilab. For consistency, we should consider only variable names which are not made

of more than 24 characters. All ASCII letters from "a" to "z", from "A" to "Z" and from "0" to

"9" are allowed, with the additional letters "%", " ", "#", "!", "$", "?". Notice though that variable

names which rst letter is "%" have a special meaning in Scilab, as we will see in section 3.5,

which presents the mathematical pre-de ned variables.

Scilab is case sensitive, which means that upper and lower case letters are considered to be

di erent by Scilab. In the following script, we de ne the two variables A and a and check that

these two variables are considered to be di erent by Scilab.



-->A = 2

A =

2.

-->a = 1

a =

1.

-->A

A =

2.

-->a

a =

1.



===================



MY COMMENT





in the languages I am familiar with BASIC, VBS (ms excel 2003) variables need to be declared as to TYPE (single precision , double, text, integer)



to make it easier to work with SET A STARTING VALUE FOR EACH VARIABLE
A Real Doctor
2010-12-23 15:40:42 UTC
myfun was never defined. Or, as the compiler sees it, myfun is an Undefined variable.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...