开发者

Gaps In Plot Of Piecewise Function in Matlab

I want to plot a piecewise function, but I don't want any gaps to appear

at the junctures, for example:

t=[1:8784];

b=(26.045792 + 13.075558*sin(0.0008531214*t - 2.7773943)).*((heaviside(t-2184))-(heaviside(t-7440)));

plot(b,'r','LineWidth', 1.5);grid on

ther开发者_如何学运维e should not be any gaps appearing in the plot between the three intervals , but they do.

I want the graph to be continueous without gaps.

Any suggestions on how to achieve that.

Thanks in advance.

EDIT

Actually, my aim is to find the carrier function colored by yellow in the figure below. I divide the whole interval into 3 intervals: 1-constant 2-sinusoidal 3- constant, then I want to find the overall function from the these three functions

Gaps In Plot Of Piecewise Function in Matlab


Of course there are "gaps". The composite function is identically zero for all t<2184, and for all t>7440. The relationships can only be non-zero inside of that interval. And you have not chosen a function that is zero at the endpoints, so how can you expect there not to be "gaps"?

What values does your function take on at the endpoints of the interval?

>> t = [2184 7440];
>> (26.045792 + 13.075558*sin(0.0008531214*t - 2.7773943))
ans =
       15.689       20.616

So look at the hat function part of this. I'll be lazy and use ezplot.

>> ezplot(@(t) ((heaviside(t-2184))-(heaviside(t-7440))),[0,8784])

Gaps In Plot Of Piecewise Function in Matlab

Now, combine this, multiplying it by a trig piece, and of course the result is identically zero outside of that domain.

>> ezplot(@(t) (26.045792 + 13.075558*sin(0.0008531214*t - 2.7773943)).*((heaviside(t-2184))-(heaviside(t-7440))),[0,8784])

Gaps In Plot Of Piecewise Function in Matlab

But if your goal is some sort of continuous function across the two chosen points in the hat function, you need to chose the trig part such that it is zero at those same two points. Mathematics is not spelled mathemagics. Wishing that you get a continuous function will not make it so.

So is your real question how to chose that internal piece (segment) as one such that the final result is continuous? If so, then we need to know why you have chosen the arbitrary constants in there. Surely these numbers, {26.045792, 13.075558, 0.0008531214, 2.7773943} all must have some significance to you. And if they are important, then how can we possibly make the result a continuous function?

Perhaps, and I'm just guessing here, you want some other result out of this, such that the function is not identically zero outside of those bounds. Perhaps you wish to extrapolate as a constant function outside of those points. But to help you, you must help us.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜