A way to get MatLab to solve inequality from left to right and not by order of operation?
Show older comments
I have this equation that I want to solve from left to right and not by order of operation, and I was wondering if there was a command to stop MatLab from automatically solving it by order of operation?
-3+1*10=8+1/3
when I solve each side separately each side should be -20 for left side and 3 for right side. Any help would be appreciated.
Answers (2)
sixwwwwww
on 13 Oct 2013
Dear MAB, you can solve equation in your desired sequence by using brackets. You can do like this:
Leftside = (-3 + 1) * 10;
Rightside = (8 + 1) / 3;
disp(Leftside)
disp(Rightside)
That's it. Good luck!
Walter Roberson
on 13 Oct 2013
0 votes
Do a bunch of string processing.
Remember the position you are in. Scan for the next operator. Convert everything between the remembered position and just before the operator into a number. If you had a pending operation, execute it with the second operator being the number you just read in. Otherwise remember which operator you just got and go back to the beginning of this loop.
Categories
Find more on Parallel Computing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!