Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Solving for a large system of equations with conditions

Subject: Solving for a large system of equations with conditions

From: Michal Kolaj

Date: 30 Mar, 2011 19:18:04

Message: 1 of 3

A,B,C and D are known m*n matrices and dx and dy are known constant scalers.
I am attempting to solve for the m*n matrix R.

-D(i,j)=-R(i,j)A(i,j) + (dR/dx)B(i,j) + (dR/dy)C(i,j)

when m < i > 1 and n < j > 1:
(dR/dx)=(R(i,j+1)-R(i,j-1))/2dx
(dR/dy)=(R(i-1,j)-R(i+1,j))/2dy

when i = 1
(dR/dy)=(R(i,j)-R(i+1,j))/dy

when i = m
(dR/dy)=(R(i-1,j)-R(i,j))/dy

when j=1
(dR/dx)=(R(i,j+1)-R(i,j))/dx

when j=m
(dR/dx)=(R(i,j)-R(i,j-1))/dx

---------
I am fairly new to matlab and I do not know how to approach this problem. Any help would be appreciated. I figured this could be done with a Ax=B solution but the size of the matrix would be huge as I would have many many x values (R values) and the majority of terms in matrix A would be 0. I also do not know of a simple way to convert my above data into such a matrix... other than doing it by hand...

Thanks again

Subject: Solving for a large system of equations with conditions

From: Torsten

Date: 31 Mar, 2011 09:48:42

Message: 2 of 3

On 30 Mrz., 21:18, "Michal Kolaj" <toomanybull...@hotmail.com> wrote:
> A,B,C and D are known m*n matrices and dx and dy are known constant scalers.
> I am attempting to solve for the m*n matrix R.
>
> -D(i,j)=-R(i,j)A(i,j) + (dR/dx)B(i,j) + (dR/dy)C(i,j)
>
> when m < i > 1 and n < j > 1:
> (dR/dx)=(R(i,j+1)-R(i,j-1))/2dx
> (dR/dy)=(R(i-1,j)-R(i+1,j))/2dy
>
> when i = 1
> (dR/dy)=(R(i,j)-R(i+1,j))/dy
>
> when i = m
> (dR/dy)=(R(i-1,j)-R(i,j))/dy
>
> when j=1
> (dR/dx)=(R(i,j+1)-R(i,j))/dx
>
> when j=m
> (dR/dx)=(R(i,j)-R(i,j-1))/dx
>
> ---------
> I am fairly new to matlab and I do not know how to approach this problem. Any help would be appreciated. I figured this could be done with a Ax=B solution but the size of the matrix would be huge as I would have many many x values (R values) and the majority of terms in matrix A would be 0. I also do not know of a simple way to convert my above data into such a matrix... other than doing it by hand...
>
> Thanks again

I think there is no way around in MATLAB: you will have to form matrix
A and vector B explicitely
and solve for x by x=A\B. MATLAB will take care of the banded
structure of your matrix A
to solve your system of equations efficiently.

In the LINPACK or LAPACK FORTRAN library, there is a special scheme to
store banded matrices,
but as far as I know, it is not supported in MATLAB.

Take care to include your boundary conditions for R at i=1, i=m, j=1
and j=n - otherwise your
system of equations will be singular.

Best wishes
Torsten.

Subject: Solving for a large system of equations with conditions

From: Steven_Lord

Date: 31 Mar, 2011 14:33:35

Message: 3 of 3



"Torsten" <Torsten.Hennig@umsicht.fraunhofer.de> wrote in message
news:2b9e8172-a28f-4517-a6b1-cd942608398c@p13g2000yqh.googlegroups.com...
> On 30 Mrz., 21:18, "Michal Kolaj" <toomanybull...@hotmail.com> wrote:
>> A,B,C and D are known m*n matrices and dx and dy are known constant
>> scalers.
>> I am attempting to solve for the m*n matrix R.
>>
>> -D(i,j)=-R(i,j)A(i,j) + (dR/dx)B(i,j) + (dR/dy)C(i,j)
>>
>> when m < i > 1 and n < j > 1:
>> (dR/dx)=(R(i,j+1)-R(i,j-1))/2dx
>> (dR/dy)=(R(i-1,j)-R(i+1,j))/2dy
>>
>> when i = 1
>> (dR/dy)=(R(i,j)-R(i+1,j))/dy
>>
>> when i = m
>> (dR/dy)=(R(i-1,j)-R(i,j))/dy
>>
>> when j=1
>> (dR/dx)=(R(i,j+1)-R(i,j))/dx
>>
>> when j=m
>> (dR/dx)=(R(i,j)-R(i,j-1))/dx
>>
>> ---------
>> I am fairly new to matlab and I do not know how to approach this problem.
>> Any help would be appreciated. I figured this could be done with a Ax=B
>> solution but the size of the matrix would be huge as I would have many
>> many x values (R values) and the majority of terms in matrix A would be
>> 0. I also do not know of a simple way to convert my above data into such
>> a matrix... other than doing it by hand...
>>
>> Thanks again
>
> I think there is no way around in MATLAB: you will have to form matrix
> A and vector B explicitely
> and solve for x by x=A\B. MATLAB will take care of the banded
> structure of your matrix A
> to solve your system of equations efficiently.

Not so, if the OP wanted to use an iterative solver like LSQR. Most of the
iterative solvers listed in HELP SPARFUN require square coefficient
matrices, but LSQR does not.

http://www.mathworks.com/help/techdoc/ref/lsqr.html

"A can be a function handle afun such that afun(x,'notransp') returns A*x
and afun(x,'transp') returns A'*x."

Sometimes it's possible to compute these matrix-vector products without
explicitly creating A or A' and I believe this is one of those situations.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us