Constant errors although the program is correct

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

Constant errors although the program is correct

monteirojp
hi, i wrote this script: function y = func(x0)
                                y = 49890/10000 + sin(x0) - x0.^2
                                end
it's a simple script but when I run the program it gives me multiple errors
and this happens in all the programs that you write. This is normal? is that
it gives error but when I call the function in the command window and assign
it to the variable it gives me the result .... Another question: how do I
call a function inside a script? Thank you!

(errors like this:
>> difuncao
error: 'x0' undefined near line 2 column 12
error: evaluating argument list element number 1
error: called from:
error:   /Users/monteirojp/Documents/FCUL - MATAPL/2º
ano/NUMERICA/exercicios em octave/difuncao.m at line 2, column 5
>>
)



--
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
Reply | Threaded
Open this post in threaded view
|

Re: Constant errors although the program is correct

Doug Stewart-4


On Fri, Dec 1, 2017 at 10:01 PM, monteirojp <[hidden email]> wrote:
hi, i wrote this script: function y = func(x0)
                                y = 49890/10000 + sin(x0) - x0.^2
                                end
it's a simple script but when I run the program it gives me multiple errors
and this happens in all the programs that you write. This is normal? is that
it gives error but when I call the function in the command window and assign
it to the variable it gives me the result .... Another question: how do I
call a function inside a script? Thank you!

(errors like this:
>> difuncao
error: 'x0' undefined near line 2 column 12
error: evaluating argument list element number 1
error: called from:
error:   /Users/monteirojp/Documents/FCUL - MATAPL/2º
ano/NUMERICA/exercicios em octave/difuncao.m at line 2, column 5
>>
)




works for me

func(1)
y =  4.8305
ans =  4.8305 



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

Re: Constant errors although the program is correct

Abhinav
In reply to this post by monteirojp
Could you elaborate your problem a little. I wrote the same script as you did and it worked fine for me. My advice is to check the following points.

1. Is your file name and function same ?

2. Did you execute your function file using exec func.m before trying to use it in command window ? 


Regards,
Abhinav Dronamraju

On Dec 2, 2017 10:46 PM, "monteirojp" <[hidden email]> wrote:
hi, i wrote this script: function y = func(x0)
                                y = 49890/10000 + sin(x0) - x0.^2
                                end
it's a simple script but when I run the program it gives me multiple errors
and this happens in all the programs that you write. This is normal? is that
it gives error but when I call the function in the command window and assign
it to the variable it gives me the result .... Another question: how do I
call a function inside a script? Thank you!

(errors like this:
>> difuncao
error: 'x0' undefined near line 2 column 12
error: evaluating argument list element number 1
error: called from:
error:   /Users/monteirojp/Documents/FCUL - MATAPL/2º
ano/NUMERICA/exercicios em octave/difuncao.m at line 2, column 5
>>
)



--
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


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

Re: Constant errors although the program is correct

Abhinav
Also, the name of the function you wrote is func and you're calling difuncao. I would advice you to follow these points below.
1. Name the file as func.m since your function name is func.
2. Go to the directory in which that file is and execute it using exec func.m
3. Then call the function with any x0 you want. 

I believe this should work properly.

Regards,
Abhinav Dronamraju

On Dec 2, 2017 10:59 PM, "Abhinav Dronamraju" <[hidden email]> wrote:
Could you elaborate your problem a little. I wrote the same script as you did and it worked fine for me. My advice is to check the following points.

1. Is your file name and function same ?

2. Did you execute your function file using exec func.m before trying to use it in command window ? 


Regards,
Abhinav Dronamraju

On Dec 2, 2017 10:46 PM, "monteirojp" <[hidden email]> wrote:
hi, i wrote this script: function y = func(x0)
                                y = 49890/10000 + sin(x0) - x0.^2
                                end
it's a simple script but when I run the program it gives me multiple errors
and this happens in all the programs that you write. This is normal? is that
it gives error but when I call the function in the command window and assign
it to the variable it gives me the result .... Another question: how do I
call a function inside a script? Thank you!

(errors like this:
>> difuncao
error: 'x0' undefined near line 2 column 12
error: evaluating argument list element number 1
error: called from:
error:   /Users/monteirojp/Documents/FCUL - MATAPL/2º
ano/NUMERICA/exercicios em octave/difuncao.m at line 2, column 5
>>
)



--
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


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

Re: Constant errors although the program is correct

monteirojp
I deceived myself to put here the error, this is the error that gives me:
error: 'x0' undefined near line 2 column 25
error: evaluating argument list element number 1
error: called from:
error:   /Users/monteirojp/Documents/FCUL - MATAPL/2º
ano/NUMERICA/exercicios em octave/func.m at line 2, column 5

the function and the file have the same name. Does it make a mistake to be
using an OS system?
Is that all the algorithms I write give me multiple errors but if I call the
function in the command window with a value gives me the result. I do not
understand.




--
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