I want my graph to be continuous

7 ビュー (過去 30 日間)
Mahmoud Chawki
Mahmoud Chawki 2021 年 8 月 9 日
コメント済み: Rik 2021 年 8 月 9 日
i want the graph to be continous. However, it is breaking form point 7 to 8 (t=7 to t=8).
as you can see from the function, at first it is a polynomial and after that it is linear, it is not taking 7 as a common point.
How can i fix that ??
.

採用された回答

Rik
Rik 2021 年 8 月 9 日
You can also let Matlab do the heavy lifting by creating an anonymous function and using fplot:
a=8.4;
v=58.8;
fun=@(t) 0 + ...
(t<=7).*(0.5*a.*(t.^2)) + ...
(t>7).*(v.*t);
fplot(fun,[0 30])
However, if you want to make the transition smooth, you will have to adjust a or v:
t=7;
[0.5*a.*(t.^2) v.*t]
ans = 1×2
205.8000 411.6000
To make those equal for some value of t, this relation must hold:
0.5*a.*(t.^2)==v.*t
a*t^2=2vt
at=2v
t=2v/a
If you want t=7, that means
7=2v/a ==> v=7a/2 ==> v=29.4
Now lets plot that one instead:
v=29.4;
fun=@(t) 0 + ...
(t<=7).*(0.5*a.*(t.^2)) + ...
(t>7).*(v.*t);
fplot(fun,[0 30])

その他の回答 (2 件)

Wan Ji
Wan Ji 2021 年 8 月 9 日
It may work if you do by following Scott MacKenzie's advice or maybe you can do like this
t = [0:1:6, 6.01:0.01:6.99, 7:1:30];
This would make your curve more smooth then.
  2 件のコメント
Scott MacKenzie
Scott MacKenzie 2021 年 8 月 9 日
@Wan Ji You are referring to my first answer which I deleted as I think it was a bit wonky. I posted a new answer which is trivial -- just change 7 to 14 in line 6. Or, there is @Rik's answer which is a bit more complicated but maintains t = 7 as the transition point.
Wan Ji
Wan Ji 2021 年 8 月 9 日
When t = 7, y encounters a gap. So a possible way is just to calculate them both and then to compare them.
a = 8.4; v = 58.8; t=0:0.1:30;
x1 = 0.5*a*t.^2; x2 = v*t;
q = x1<x2;
x = x1.*q + x2.*~q;
plot(t,x)
quite easy to find that the intersection point is 14.2, as mentioned by @Scott MacKenzie.

サインインしてコメントする。


Scott MacKenzie
Scott MacKenzie 2021 年 8 月 9 日
You need to determine the point where the two functions intersect and then use that point in line 6 as the transition between the two curves. That point is t = 14, which (luckily) happens to be an integer. So, change 7 to 14 in line 6 and you're good to go:
  3 件のコメント
Bjorn Gustavsson
Bjorn Gustavsson 2021 年 8 月 9 日
@Rik, Or simply continue along the tangent at the transition...
Rik
Rik 2021 年 8 月 9 日
@Bjorn True, in which case v would have to be set at a*t.

サインインしてコメントする。

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by