Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


Matt J
Posts:
4,994
Registered:
11/28/09


Re: I have 51 linear equations, consisting of 51 unknowns. How to solve it in Matlab by using matrix?
Posted:
May 27, 2013 11:29 AM


"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.



