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!