Heaviside duty cycle symbolic function
조회 수: 2 (최근 30일)
이전 댓글 표시
I'm trying to write a symbolic function to simulate an electrical device's electricity usage. Since the electricity is billed different price at different time of the day, I wanted to write a symbolic function with a duty cycle of 0.125 (on 15 minutes, off 1h45 minutes). I thought it would be easy with matlab.
syms x
fridge = 0;
for ii = 0:12
fridge = fridge + heaviside(x-(ii*2)) - heaviside(x-(0.25+(ii*2)));
end
fplot(fridge,[0, 24])
There are some parts of the functions not plotting correctly, like
heaviside(x-6)-heaviside(x-6.25)
Any ideas what could be wrong?
EDIT: When I plot my function from 0 to 12, it seems to work fine but when plotted from 0 to 18 it stops working.
댓글 수: 0
채택된 답변
Nachiket Katakkar
2017년 2월 23일
The fplot appears to miss certain values for the range of values you have specified. The reason for this apparent ambiguity is that the number of function evaluations is set to the default value of the " MeshDensity " parameter (23) and hence certain critical points seem to have been missed for the range [0,24].
To obtain correct results I would suggest increasing the MeshDensity value to 60:
>> fplot(fridge,[0, 24], 'MeshDensity', 60)
Setting the value to 61, ensures that the value of 1/2 (at x == 6) is correctly represented as well:
>> fplot(fridge,[0, 24], 'MeshDensity', 61)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Assumptions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!