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:
I have 51 linear equations, consisting of 51 unknowns. How to solve it in Matlab by using matrix?

Subject: I have 51 linear equations, consisting of 51 unknowns. How to solve it in Matlab by using matrix?

From: J K

Date: 27 May, 2013 14:26:10

Message: 1 of 5

http://www.flickr.com/photos/94031835@N02/8854172149/

I need to solve the temperature distribution of a plate. And the number of nodes are 51. Hence 51 equations.

As you can see in the link, some of the equations are shown.

How to solve that using Matlab?

I know I can always separate the temperature, like [A][T]=[B]
T=inv(A)*(B)

But let say I don't want to separate the equations. I want to leave it that way. How can I solve it?

Subject: I have 51 linear equations, consisting of 51 unknowns. How to solve it in Matlab by using matrix?

From: Matt J

Date: 27 May, 2013 15:04:10

Message: 2 of 5

"J K" wrote in message <knvqe2$md$1@newscl01ah.mathworks.com>...
> http://www.flickr.com/photos/94031835@N02/8854172149/
>
> I know I can always separate the temperature, like [A][T]=[B]
> T=inv(A)*(B)

It would be better to do
 T=A\B

 
> But let say I don't want to separate the equations. I want to leave it that way. How can I solve it?
===============

What do you mean by "separate the equations"?

Subject: I have 51 linear equations, consisting of 51 unknowns. How to solve it in Matlab by using matrix?

From: J K

Date: 27 May, 2013 15:19:11

Message: 3 of 5

> What do you mean by "separate the equations"?

Let say I have 3 equations with 3 unknowns.
1x1 + 2x2 + 3x3 = 100
4x1+ 5x2 + 6x3 = 200
7x1 + 8x2 + 9x3 = 300

Normally in Matlab, you will do this command in order to solve x1,x2,x3

p=[1 2 3; 4 5 7; 7 8 9]'
q=[100 200 300]'
x=inv(p)*q

But let's say I don't want to use the method/way that I write. What other options that I have in order to solve for the 51 unknowns?

Subject: I have 51 linear equations, consisting of 51 unknowns. How to solve it in Matlab by using matrix?

From: Matt J

Date: 27 May, 2013 15:29:10

Message: 4 of 5

"J K" wrote in message <knvthf$87h$1@newscl01ah.mathworks.com>...
> > What do you mean by "separate the equations"?
>
> Let say I have 3 equations with 3 unknowns.
> 1x1 + 2x2 + 3x3 = 100
> 4x1+ 5x2 + 6x3 = 200
> 7x1 + 8x2 + 9x3 = 300
>
> Normally in Matlab, you will do this command in order to solve x1,x2,x3
>
> p=[1 2 3; 4 5 7; 7 8 9]'
> q=[100 200 300]'
> x=inv(p)*q


No. Once again you would normally NOT use inv(). The more efficient way is to use backslash

  x=p\q

Compare the following

>>A=rand(3000);

>> tic; inv(A)*A(:,1); toc
Elapsed time is 1.956851 seconds.

>> tic; A\A(:,1); toc
Elapsed time is 0.623370 seconds.
>>

> But let's say I don't want to use the method/way that I write. What other options that I have in order to solve for the 51 unknowns?
================

You could also do

 x=linsolve(p,q);

If your equations have special structure, LINSOLVE can take advantage of this. See doc linsolve.

Subject: I have 51 linear equations, consisting of 51 unknowns. How to solve it in Matlab by using matrix?

From: Steven_Lord

Date: 28 May, 2013 14:45:53

Message: 5 of 5



"J K" <chemical2romance90@yahoo.com> wrote in message
news:knvthf$87h$1@newscl01ah.mathworks.com...
>> What do you mean by "separate the equations"?
>
> Let say I have 3 equations with 3 unknowns.
> 1x1 + 2x2 + 3x3 = 100
> 4x1+ 5x2 + 6x3 = 200
> 7x1 + 8x2 + 9x3 = 300
>
> Normally in Matlab, you will do this command in order to solve x1,x2,x3
>
> p=[1 2 3; 4 5 7; 7 8 9]'
> q=[100 200 300]'
> x=inv(p)*q
>
> But let's say I don't want to use the method/way that I write. What other
> options that I have in order to solve for the 51 unknowns?

If you want to leave the equations in the equation form (the first section
above) instead of converting them into the matrix-based form (the second
section above), you could do this using SOLVE from Symbolic Math Toolbox. If
that's not an option then you MUST convert them from the equation form to
the matrix form to solve them, and as Matt J said you should use the
backslash operator NOT the INV function to solve the system.

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

Tags for 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