- #1

playboy

## Homework Statement

Let A and B be invertible n×n matrices and b be an n×1 vector.

Write a MATLAB function with inputs (A,B, b) to solve the equation x=B^−1*(2A^−1 + 1)b

Make use of functions "LU Facotrization, Forward Substituion and Backwards Substitution" and DO NOT calculat any matrix inverse.

## Homework Equations

PLEASE IGNORE THIS PART FOR NOW AND SKIP TO

## The Attempt at a Solution

Well, I came up with the functions for LU Facotrization, Forward Substituion and Backwards Substitution;

LU Facotrization:

function [L,U]=lufactor(A)

n=length(A)

U1=A

L1=eye(n);

..for p=1:n

....for q=p+1:n

......L(q,p)=U(q,p)/U(p,p)

......U(q,p:n)=U(q,p:n)-U(p,p:n)*L(q,p)l

....end

..end

Forward Substition:

function x=forsub(L,b)

[n,n]=size(L);

x=zeros(n,1);

..for i=1:n

..... x(i)=(b(i)-L(i,1:i-1)*x(1:i-1)/L(i,i)

..end

Backwards Substition:

function x=baksub(U,b)

[n,n]=size(L);

x=zeros(n,1);

..for i=n:-1:1

..... x(i)=(b(i)-L(i,i+1:n)*x(i+1:n)/U(i,i)

..end

## The Attempt at a Solution

I wrote the above functions, so that is a start,

But apart from trying to write the code, Im kind of lost in understanding the math - which is much more important.

I want to LU-factorize A and B to get and upper and lower matrix for each of A and B.

With these matracies, how would I go abouts get it's inverse?

Forword substitution solves for x in Lx = b

and

Backword substitutions solves for x in Ux=b

I do not know where to go from here

Could somebody help me out please?