solving multiple equations
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Walter Roberson
2012-2-2
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');
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Special Values 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!