solving multiple equations
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
This is rather simple. Im just begining to use matlab and I was trying to find the equation to a line that intersected at (1,4) and (2,2). this is easily done by hand but I wanted to save time. I entered the code: [m,b]=solve('m+b=4','2*m+b=2')
this gave me: m= 6 b= -2 . This is obviously wrong, if you plug in those answers in the second equation you get "10=2". I tried changing the code to [b,m]=solve('m+b=4','2*m+b=2'). (Notice I wrote [b,m] instead of [m,b]) And then I got the correct result: m=-2, b= 6. Why does this happen? What did I do wrong?
0 Kommentare
Antworten (1)
Walter Roberson
am 2 Feb. 2012
This is expected. solve() does not look at the names of the output variables to determine the order in which to output the variables. When you do not specify the order of the variables in the solve() call, solve() uses symvar() to locate the variables. symvar() has an unusual ordering choice that happens to choose 'b' before 'm'
What you should do is specify the order of the variables:
[m,b] = solve('m+b=4','2*m+b=2','m','b');
Siehe auch
Kategorien
Mehr zu Special Values finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!