How to turn a function with a for loop into a recursive function

1 次查看(过去 30 天)
Hello, I have a task to write a recursive function, that solves a system with an upper-triangular coefficient matrix. I mean, to solve the system: Ax=b, when A is an upper-triangular coefficient matrix
I wrote a function using for loop, howover I don't know how to turn it into a recursive function. Here's my code:
function x=uppermatsolve(M,b);
x=zeros(size(b));
[n,m]=size(M);
x(n,:)=b(n,:)/M(n,n);
for k=n-1:-1:1
x(k,:)=(b(k,:)-M(k,k+1:n)*x(k+1:n,:))/M(k,k);
end
Any help is greatly appreciated!

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by