Plotting differential equations, need help

y = diff(sin(2*pi*t))./diff(t);
plot(t,y)
Remember diff() shortens the length of your vector by one so you will need to define a new time vector to plot against. ---- how do i do this?
thank you

 採用された回答

Yu Jiang
Yu Jiang 2014 年 10 月 6 日

1 投票

plot(t(2:end),y)

8 件のコメント

Andrew
Andrew 2014 年 10 月 6 日
yeah works for sin(), however when you try to do it for t^2. come sup with error.
Geoff Hayes
Geoff Hayes 2014 年 10 月 6 日
What is the error, and the line(s) of code that you are using?
Andrew
Andrew 2014 年 10 月 6 日
using your fix for the plot(t(2:end),y), as plot(t,y) doesn't work
Error using diff
Difference order N must be a positive integer scalar.
Andrew
Andrew 2014 年 10 月 6 日
y=diff(t,t);
plot(y,t)
returning an error
Yu Jiang
Yu Jiang 2014 年 10 月 6 日
編集済み: Yu Jiang 2014 年 10 月 6 日
what is the t vector? What is the expected result from y=diff(t,t)?? This is different from you original post.
I tried the following on my machine, and it worked
t = linspace(-10,10,100);
y = diff(sin(2*pi*t))./diff(t);
plot(t(2:end),y)
Andrew
Andrew 2014 年 10 月 6 日
yeah it works, but when u integrate that technique into a different equation, it triggers an error.
Andrew
Andrew 2014 年 10 月 6 日
its ok, i fixed it. thanks for your help sir.
Yu Jiang
Yu Jiang 2014 年 10 月 6 日
You are welcome.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeNumerical Integration and Differential Equations についてさらに検索

質問済み:

2014 年 10 月 6 日

コメント済み:

2014 年 10 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by