Bug with piecewise?

조회 수: 4 (최근 30일)
Dion Richardson
Dion Richardson 2019년 8월 28일
댓글: Dion Richardson 2019년 8월 30일
I'm no expert at all in mathematics but I wrote a simple program that doesn't seem to get the answer that I'd expect.
It provides:
ans =
6 - time
time + 6
as the only solutions, however shouldn't 0 be a solution assuming time > 6?
This could just be poor programming on behalf of me and if it is how would I get the required answer.
  1. Is this a bug?
  2. Am I making a mistake?
  3. If this is a mistake how can I fix it?
This is supposed to simulate a 1D particle traveling at a fixed velocity of 1 towards origin (0). I understand the answer is relatively simple to do by hand, however I have this repeated with more complicated variables in a larger equation that would be incredably tedious and unmaintainable to solve by hand.
syms position time;
speed = piecewise(position > 0,-1,position < 0,1,0);
solve(int(speed,time) + 6 == position,position) %6 is starting offset

채택된 답변

Walter Roberson
Walter Roberson 2019년 8월 28일
편집: Walter Roberson 2019년 8월 29일
When position is 0 then speed is 0. int(0,time) is 0 plus a constant. Add 6 and the result is 6 plus a constant. The result is not equal to 0 unless the constant is -6. Which is possible, but int() always uses constant 0 for indefinite integration.
  댓글 수: 9
Walter Roberson
Walter Roberson 2019년 8월 29일
I filed a bug report about the discrepancy
Dion Richardson
Dion Richardson 2019년 8월 30일
Sweet, thank you =)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by