File Exchange Pick of the Week

September 13th, 2007

MATLAB Basics video: Solving linear equations

This is one in a series of videos covering MATLAB basics. It is meant for the new MATLAB user.

This video covers how to convert two equations into matrix form and then solve them in MATLAB. This is one of the most basic problems in linear algebra. It is handled nicely in MATLAB, MATrix LABratory. This video shows how to define a small matrix and vector.

Find the files here.

Other videos have been gathered here:
http://blogs.mathworks.com/pick/category/video/

Other MATLAB Basics posts have been gathered here:
http://blogs.mathworks.com/pick/category/matlab-basics/

4 Responses to “MATLAB Basics video: Solving linear equations”

  1. Sébastien replied on :

    Hi,

    I understood your video, but how to do it if the coefficients of the equations are vectors? For example, if I have:

    gamma1(:,1)= nc2(:,1)*gamma2(:,1)+nc3(:,1)*gamma3(:,1)
    vega1(:,1)=nc2(:,1)*vega2(:,1)+nc3(:,1)*vega3(:,1)

    and I want to find nc2 and nc3?

    Thanks a lot!

  2. Doug replied on :

    Sebastien,

    You will want to store those coefficients into a dedicated matrix. You will have to use subscripting to get them into the matrix from those vectors.

    Doug

  3. Sébastien replied on :

    Well, that’s what I tried:
    Let’s say that y=A*x
    In my case, I have:

    A=[gamma2(:,1),gamma3(:,1);vega2(:,1),vega3(:,1)];
    y=[gamma(:,1);vega(:,1)];
    x=A\y;
    But with that code x has only two values, and I want x to be a vector. Do you see my problem? Thanks a lot

  4. Doug replied on :

    What are the dimensions of A and y once they are constructed?

    I suspect that they are

    A = 2×2
    y = 2×1

    If that is the case,
    x = 2×1

    That is expected.

    Doug

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Bob, Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

  • Zach: Hi Doug and Les, I didn’t have a lot of time to mess with this, but I did find a work-around. I plotted...
  • hamed: k
  • Les: @Zach This isn’t exactly what you are looking for but at least it puts all three parameters on the same...
  • Zach: Thanks for your suggestions Doug. I’ll give that a shot and see what happens. I’ve seen many of...
  • Doug: @Zach, I would say to use plotYYY, because that is close to what you want, but using depth as Y makes sense....
  • Doug: @Teja, I think this will work: http://www.mathworks .com/access/helpdesk /help/techdoc/ref...
  • Gify: merry christmas :) nice christmas tree! Regards, Janet Gify
  • Teja: Dear Doug Is there anyway to plot a surface from nonuniform data without meshgrid and griddata? Basically i...
  • Zach: I’m working with geophysical data, so I’d like to produce a depth profile. The y-axis would be...
  • Doug: @Ashok First, please do not use variable names that are MATLAB commands (std and mean). Second, p(j) should be...

These postings are the author's and don't necessarily represent the opinions of The MathWorks.