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.

  • oleg: The author has implemented skewness, kurtosis and checks answering appropriately to the critic.
  • Ashok: how to store 10 or more random number in a loop a loop for i = 1:n mean(i) = input(’enter the mean value...
  • Ben: Doug, Thanks for the very helpful videos! Uitables seem like a convenient way to make a customized property...
  • oleg: Allstats has no checks, no comments and could also be improved (talking about prctile implementatio). Not to...
  • Todd: Additional information and a link to download free MATLAB and Simulink LEGO MINDSTORMS NXT code can be found at...
  • Doug: @Leo, Here is the “English version” of that code. “vec = []” makes an empty variable...
  • leo: Dear Doug I have a question in your code ‘October 9th, 2009 at 13:53′ vec = []; vec = [vec val]; I...
  • Shanker Keshavdas: You sir, are a gentleman and a scholar… No really, helped me out a lot. As to what is...
  • Quan Zheng: how can I get a copy of stepspecs.m?
  • Doug: @Lucy I think this is what you seek to move a line with the mouse in MATLAB. http://blogs.math...

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