m file that calls function nraizes(a) from another m file.
clear functions;
clc;
x = input('Insert value for a? ') ;
% call to nraizes()
w = nraizes(x)
clear functions;
nraizes.m file with nraizes() function:
printf("\n\n");
printf("nraizes por André Castro - UAB 901396");
printf("\n");
printf("Usar na próxima prompt: nraizes(valor numérico)");
printf("\n");
function n = nraizes(a)
% limpar a memoria de todas as vars e funções
clear functions;
clc;
% intervalo para x
x = 0:.1:25;
% ambas as funções h(x) e g(x)
h = @(x) cos(x);
g = @(x) exp(a*x)-1;
% traçar linha na origem das abcissas
or = x;
or(:) = 0;
% gráfico
plot(x, [h(x);g(x);or]);
axis([0, 25, -1, 1])
title("h(x),g(x)");
grid on;
printf("Fim do Script");
printf("\n");
% limpar a memoria de todas as vars e funções
clear functions;
endfunction
It always throws the following error:
warning: function 'nraizes' defined within script file '/Users/andrecastro/0_Thawed/1_UAB/1 UCS_INFORMATICA/Computacao Numerica/0 2015-2016_CN/1 Algoritmos_Octave/nraizes.m'
error: invalid use of script /Users/andrecastro/0_Thawed/1_UAB/1 UCS_INFORMATICA/Computacao Numerica/0 2015-2016_CN/1 Algoritmos_Octave/nraizes.m in index expression
error: called from:
error: /Users/andrecastro/0_Thawed/1_UAB/1 UCS_INFORMATICA/Computacao Numerica/0 2015-2016_CN/1 Algoritmos_Octave/script.m at line 19, column 7
I don't undestand why. Both .m files are in same path.
nraizes(which is a function that you wrote). You say there is a function named nraizes but you did not wrote a function, you wrote a script. To be a function, it needs to start with a function definition. - carandraug