solving matrix equation '[A]*(x)=(b) with variables at the x and b vectors

hello i dont know how to solve for ex A= [1 2;2 1]
x=[1;x]
b=[0;u]
the solution of this is x=-0.5, u=3/2 but how can i solve it by using Matlab? i will be greatfull to helpers

2 Comments

It's awkward to use x both for a 2x1 vector and for a scalar. The question would be clearer if you used two different symbols - say x = [1; v].
In what way do you want to use MATLAB? The question is easy to solve on paper, so what kind of contribution do you think MATLAB will make?
of course i had mistake with the vector name x (i named the voctor as x and the variable x...)

Sign in to comment.

 Accepted Answer

You have to convert the equation into a proper linear form.
First you multiply x with A to get
1 + 2x = 0
2 + 1x = u
Then you transform the equations such that all unknowns are on the left side
2x = -1
1x - u = -2
Finally you code this as matrix and vector and use Matlab's matrix left divide \ to solve M*c = [x ;u];
M = [ 2 0; 1 -1]; c = [-1; -2]
M\c
ans =
-0.5000
1.5000

2 Comments

1. Minor edits for readability.
2. You had the wrong c vector, by miscopying the sign of the constant term on the second equation. Repaired that, to yield a correct final solution.
Finally, since I'm too lazy to check your algebra, I checked using syms... (Paper? Pencil? What are those barbaric things?)
A = sym([1 2;2 1]);
syms x u
solve(A*[1;x] - [0;u],x,u)
ans =
x: [1x1 sym]
u: [1x1 sym]
xu = solve(A*[1;x] - [0;u],x,u);
xu.x
ans =
-1/2
xu.u
ans =
3/2
Barbaric indeed, but in this case very fast. Since the first equation does not involve u, the solution drops out of the first two lines of the answer, and there's no need to recast it as a new matrix problem. But maybe it's a homework problem and merely getting the answer misses the point.

Sign in to comment.

More Answers (2)

thanks! i will cheack it out to see if everything is cleared for me. cause my real calculate is alot more difficult from the ex. i gave but it helped me!
ok im in a little problam, i trying to do this on a bigger matrix and vectors, im doing the exact same thing as you untill row 3, im getting the answer, but now, whats should i do? my problam is with 18 equations with 18 variables.......): so till row 3 everything goes great, but im getting confused when i need to convert the example dimensions to 18X18 dimensions..

Asked:

on 24 Nov 2014

Answered:

on 24 Nov 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!