How to return output argument in matlab?

0

I created a function to calculate a linear system with 5 unknowns (A1 to A5), which has as output argument 'Ai' and input 'A and b' which are respectively a Matrix and Vector. The values of A and b are assigned, but I did not put it here.

At the end of the function I get the values of Ai (which are 5). But I need to use the Ai values outside of my function!

FOLLOW THE FUNCTION:

function Ai = gauss(A,b)

%% dimensao da matriz. linha, coluna

[l,c]=size(A); 

%% eliminação

for i=1:l-1

for j=i+1:l;

%% definição da constante para zerar as linhas

constante=A(j,i)/A(i,i); 

for k=i+1:l;

%% operação linear para eliminar as linhas

A(j,k)=A(j,k)-constante*A(i,k); 

end

A(j,i)=0;

b(j)=b(j)-constante*b(i);

end

end  

%% Resolução do sistema

%% função Ai recebe um array de zeros

Ai=zeros(l,1);

fprintf('SOLUÇÃO DO SISTEMA:\n\n');

for i=l:-1:1;

    soma=0;

    for k=i+1:l;

        soma=soma+A(i,k)*Ai(k);

    end

    Ai(i)=(b(i)-soma)/A(i,i);

end

end

y=x^2+x;

I want to multiply each value of Ai (which is 5) by the expression below that is outside the gauss function.

y=x^2+x;

But how to use the values of Ai out of function?

    
asked by anonymous 04.11.2017 / 02:58

1 answer

0

Input and output is very simple in Matlab. But to answer you, you need to put where you are using Ai and how you are calling your function.

After all, if you are using the function to calculate something, it is necessary to call it and give the input values A and b in some way. And it will inevitably have the output of Ai , which you may be suppressing.

If you have questions about working with Matlab, the matlab site has good resources and several examples. Maybe it's an idea to take a look before embarking on bigger projects. In addition, a quick search in google returns a lot of material, but in english it has a lot more resources

    
04.11.2017 / 12:36