help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Octave function error


From: Kai Torben Ohlhus
Subject: Re: Octave function error
Date: Mon, 30 Mar 2020 18:22:13 +0900
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0

On 3/30/20 3:23 PM, Adrg01 wrote:
> Hi
> I'm a new user of octave and i'm getting an error while trying to use a
> function. I've checked the forum for similar error. Even though the error in
> my case is same, i'm pretty sure it is not a formatting error and I've
> written the code in OctaveGUI.
> 
> octave:9> val = costFunc(x,y,theta)
> error: 'costFunc' undefined near line 1 column 7
> 
> Here is my code
> <https://octave.1599824.n4.nabble.com/file/t373708/func.png> 
> 
> function j=costFunc(x,y,theta)
> m=length(theta)+1
> yPred=(theta')*x
> temp=(yPred-y).*(yPred-y)
> j=(1/2*m)*(sum(temp));
> endfunction
> 

Did you save "costFunc" as m-file "costFunc.m" in the current working
directory?  You can assure this by typing

   >> pwd
   ans = /home/siko1056/work

   >> which costFunc
   'costFunc' is a function from the file /home/siko1056/work/costFunc.m

Then you have to define x, y, and theta and can call "costFunc" as you
have done before.

HTH,
Kai





reply via email to

[Prev in Thread] Current Thread [Next in Thread]