How to use function return in Scilab or MatLab?

0

I'm doing a simple numerical program.

But I can not use return of functions in Scilab can anyone help me?

The function has to solve a calculation and then return the value for this variable to continue to be manipulated by the program.

The main function is integral()

function funcao (x)
         x^2
         return F
endfunction

a=2
b=4
function integral()
    x=(a+b)/2 *0,222
    funcao(x)
    disp(F)
endfunction
    
asked by anonymous 11.06.2015 / 13:03

2 answers

1

Functions in Matlab can have a single or multiple output. A single output:

function y = media(x)
if ~isvector(x) %testa se é um vetor
    error('A entrada tem que ser um vetor')
end
y = sum(x)/length(x); 
end

Multiple outputs:

function [m,s] = stat(x)
n = length(x);
m = sum(x)/n;
s = sqrt(sum((x-m).^2/n)); %calcular o desvio
end

How to use:

valores = [12.7, 45.4, 98.9, 26.6, 53.1];
[ave,stdev] = stat(valores)

The output would look like this:

ave =
   47.3400
stdev =
   29.4124

Your problem would be something like this:

a=2
b=4

function F = integral(a,b)

    x = (a+b)/2*0.222
    F = funcao(x)

end

function y = funcao (x)

         y = x^2
end

For more information see here .

    
12.06.2015 / 01:28
0

I do not handle anything from matlab, but I think your program should look like this:

function funcao (x)
    return x ^ 2
endfunction

a = 2
b = 4

function integral()
    x = (a + b) / 2 * 0.222
    f = funcao(x)
    disp(f)
endfunction
    
12.06.2015 / 00:36