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 Ax = B when some values of x are known

Subject: Solving Ax = B when some values of x are known

From: Derrek

Date: 11 Mar, 2012 07:11:26

Message: 1 of 6

I am attempting to solve Ax = B where A is a 28,441 by 28,441 matrix, and B is a column vector with 28,441 known elements. I am trying to solve for x. However, I already know a few of the values of x. When I try to solve x= A\B I get numbers that are many orders of magnitude larger than they should be. In my case the maximum value found for x should be 300, but I am getting results up to 60,000.

The answer is incorrect because there are initial conditions (the known x values) that I am not sure how to define. The program is solving for x values that are already known, and this is screwing up my results. I need to somehow be able to incorporate the known values into the x vector and solve for the unknown ones at the same time. What's the best method to go about this?

Thanks for the help.

Subject: Solving Ax = B when some values of x are known

From: Nasser M. Abbasi

Date: 11 Mar, 2012 07:28:12

Message: 2 of 6

On 3/11/2012 1:11 AM, Derrek wrote:
> I am attempting to solve Ax = B where A is a 28,441 by 28,441 matrix, and B is a
>column vector with 28,441 known elements. I am trying to solve for x. However,
>I already know a few of the values of x. When I try to solve x= A\B I get numbers
>that are many orders of magnitude larger than they should be. In my case the
>maximum value found for x should be 300, but I am getting results up to 60,000.
>
> The answer is incorrect because there are initial conditions (the known x values)
>that I am not sure how to define. The program is solving for x values that
>are already known, and this is screwing up my results. I need to somehow be
>able to incorporate the known values into the x vector and solve for the
>unknown ones at the same time. What's the best method to go about this?
>
> Thanks for the help.


Why not remove the corresponding row(s) and column(s) from A for those
known 'x' values (also the corresponding entries in B).

ie. you have added equations to your system, where there is nothing to solve.

Why?

--Nasser

Subject: Solving Ax = B when some values of x are known

From: Derrek

Date: 11 Mar, 2012 07:52:25

Message: 3 of 6

Because the corresponding entries in A and B are several thousand in number, and they are spread throughout the matrix with no discernible pattern. The known values are not adjacent to each other. They are more or less randomly spread out.

Subject: Solving Ax = B when some values of x are known

From: Nasser M. Abbasi

Date: 11 Mar, 2012 08:15:18

Message: 4 of 6

On 3/11/2012 1:52 AM, Derrek wrote:
> Because the corresponding entries in A and B are several thousand in number,
>and they are spread throughout the matrix with no discernible pattern. The known
>values are not adjacent to each other. They are more or less randomly spread out.

So, you have several thousands of entries that are not needed in
your A matrix.

More of a reason to remove them. But it is your code, you can
do anything you want. Just leave them there if that is easier
for you.

--Nasser

Subject: Solving Ax = B when some values of x are known

From: Bruno Luong

Date: 11 Mar, 2012 08:45:14

Message: 5 of 6

"Derrek " <derrek.igleheart682@topper.wku.edu> wrote in message <jjhj6t$kg2$1@newscl01ah.mathworks.com>...
> I am attempting to solve Ax = B where A is a 28,441 by 28,441 matrix, and B is a column vector with 28,441 known elements. I am trying to solve for x. However, I already know a few of the values of x. When I try to solve x= A\B I get numbers that are many orders of magnitude larger than they should be. In my case the maximum value found for x should be 300, but I am getting results up to 60,000.
>

Let [m n] size of A, and [n 1] size of x.

If you know - said the first 10 value of x, decompose the system

x = [knownx; y], where
knownx is 10 x 1,
y is (n-10) x 1;

A = [A1 A2] where
A1 is m x 10
A2 is m x (n-10).

Your system becomes

A1*knownx + A2*y = B

So

A2*y = B - A1*knownx

Just solve the later normally then plug y to x.

Bruno

Subject: Solving Ax = B when some values of x are known

From: Matt J

Date: 11 Mar, 2012 15:19:13

Message: 6 of 6

"Derrek " <derrek.igleheart682@topper.wku.edu> wrote in message <jjhljp$qvo$1@newscl01ah.mathworks.com>...
> Because the corresponding entries in A and B are several thousand in number, and they are spread throughout the matrix with no discernible pattern. The known values are not adjacent to each other. They are more or less randomly spread out.
=================

This is similar to the response Bruno already gave, but I wanted to emphasize that this approach does not require the known values of x be adjacent to each other, as you seem to be concerned about above. The only thing you need to know is a logical or numeric vector of indices, call it idx, of the known values,

Aknownx=A(:,idx)*knownx;
A(:,idx)=[];

unknownx=A\(B-Aknownx);

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