can anyone suggest me a command that talks about how matlab performed an arithmetic operation (its steps to give us the final result) ?

조회 수: 7 (최근 30일)
such a given operation (1/2+1/3)/456*789
  댓글 수: 1
Steven Lord
Steven Lord 2018년 9월 30일
People have commented about potential ways to do what you've asked, but no one has yet asked why you want to know this information?

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2018년 9월 25일
  댓글 수: 13
diadalina
diadalina 2018년 9월 30일
MR.Stephen if i want to use the the debugging tools.for this operation how can i do this ?
Stephen23
Stephen23 2018년 9월 30일
편집: Stephen23 2018년 9월 30일
"if i want to use the the debugging tools.for this operation how can i do this"
I don't know if it is possible to do exactly what you want. I wrote that the closest solution might be to use the debugging tools (in particular the step in command). But how useful that would be depends on what commands in your code are functions and which ones are compiled/inbuilt. But there is nothing stopping you from giving it a try:

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Bruno Luong
Bruno Luong 2018년 9월 26일
편집: Bruno Luong 2018년 9월 26일
Here is an idea, replace the number of your expression by functions (that return a scalar) and print out the order
% (1/2+0/3)/456*789
(f(1)/f(2)+f(0)/f(3))/f(456)*f(789)
function x = f(x)
disp(x)
end
When run it you'll get
>> printorder
1
2
0
3
456
789
ans =
0.8651
Insert the operator(s) (there is only one right way to do it) you'll get the polish-reverse notation of the expression
1; 2; /; 0; 3; /; +; 456; /; 789; *
Meaning the expected specified evaluation order we told you.
  댓글 수: 8
James Tursa
James Tursa 2018년 9월 30일
So, getting caught up on this thread. My comments were general comments about operator precedence, not about how MATLAB decides how to evaluate an expression, particularly one involving function calls. Bruno makes that point as well in his Answer. This entire thread about which order MATLAB evaluates functions in an expression is a related topic but is not the same thing as operator precedence, and my comments should not be taken to imply anything about which order function calls are evaluated.
Bruno Luong
Bruno Luong 2018년 9월 30일
From the order of the evaluation of the operands one can infer the order of the operations. Actually I have double checked the logic by hacking the operations as well to display something when it's invoked. The result just match well all the cases I tested with what I have expected and the documentation.

댓글을 달려면 로그인하십시오.


Bruno Luong
Bruno Luong 2018년 9월 26일
편집: Bruno Luong 2018년 9월 26일
f(3)^f(4) would have to be done first
That's the case, the power is the first to be performed (among operators), but it's not saying the operands f(3) and f(4) are evaluated first.

카테고리

Help CenterFile Exchange에서 Exponents and Logarithms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by