Heaviside duty cycle symbolic function

4 visualizaciones (últimos 30 días)
anonymoushippo
anonymoushippo el 21 de Feb. de 2017
Comentada: anonymoushippo el 24 de Feb. de 2017
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.

Respuesta aceptada

Nachiket Katakkar
Nachiket Katakkar el 23 de Feb. de 2017
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)

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by