Solving same symbolic equation but getting different results?

조회 수: 2 (최근 30일)
Yilmaz Baris Erkan
Yilmaz Baris Erkan 2018년 1월 30일
댓글: John D'Errico 2018년 1월 30일
if true
% clear,clc
format short
syms dy v0 t theta g
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
eq1 = (dy == v0*t*sin(theta) - 1/2*g*t^2);
T1 = solve(eq1,t)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dy = v0 * t *sin(theta) - 1/2*g*t^2;
T2 = solve(dy,t)
end
The code I am struggling to interpret is given above. I would expected the same result from both ways, however apperantly, it is not the case. Even though there might be a trivial distinction that I am missing, I would appreciate if anyone enlightens me about it.
Thank you in advance.
  댓글 수: 1
Star Strider
Star Strider 2018년 1월 30일
Please describe what you want to do.
Do you want to integrate ‘eq1’ as a differential equation?

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

채택된 답변

John D'Errico
John D'Errico 2018년 1월 30일
편집: John D'Errico 2018년 1월 30일
They are NOT the same equations!!!!!!!!
There is a difference. In the first equation, MATLAB is told that dy is a constant. The NAME of the equation is eq1. This is a quadratic equation with a constant term.
Now, look at the second equation.
You named it dy. dy is NOT seen as a constant here, but a container for the equation itself, much like eq1 was before. Importantly, see there is NO constant term in equation dy.
Note that even though you defined dy as a symbolic variable before, the line:
dy = v0 * t *sin(theta) - 1/2*g*t^2;
overwrites the value of dy. So when you try to "solve" dy, it solves dy by setting it to zero, and solving for t, thus dy==0.
What is the solution there? Clearly, that is either t=0, or t=2*v0*sin(theta)/g.
There is indeed a difference, and it is important to recognize.
  댓글 수: 2
Yilmaz Baris Erkan
Yilmaz Baris Erkan 2018년 1월 30일
Thank you for showing me difference with detail. It helped me a lot.
John D'Errico
John D'Errico 2018년 1월 30일
Its kind of subtle, and I admit that they LOOK the same.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by