0
I created a function to calculate a linear system with 5 unknowns (A1 to A5), which has as an 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 here.
At the end of the function I get the Ai values (which are 5). However I need to use the Ai values outside of my function!
FOLLOWS BELOW 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 (that is 5) by the expression below that is outside the function Gauss.
y=x^2+x;
But how to use Ai values outside the function?
I am using Ai within the function 'Gauss'. Yes, I am using the function to calculate the unknowns of a linear system.
– Estudante
Obg for the tips
– Estudante
@Student you are creating (and maybe using)
Ai
within the functiongauss
, but by your description you want to use these values outside the Gauss function. Is this part out ofgauss
I need to see your problem.– Guto
THE COMPLETE FUNCTION IS:
– Estudante
Ask your question. It’s clearer this way.
– Guto
READY GUTO, THE QUESTION HAS BEEN EDITED!!!!! I HOPE IT IS CLEAR NOW
– Estudante
@Student is not completely clear yet. You put as you want to use, but not as you are using. Where to function
gauss
is it called? With what values to test? Use a [mcve], this helps in solving the problem. For example, your function is not working with matrices larger than 1 dimension!– Guto
@Student I must say that the function
gauss
in itself is not necessary to solve your problem. A [mcve] can be obtained without the 'resolution' part of the function, only with a Matrix within any function. This still doesn’t solve the problem I asked you: how you are calling the function (be it Gauss or a simple example with a function that has a Matrix that you want to save).– Guto