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
采纳的回答
plot(t(2:end),y)
8 个评论
yeah works for sin(), however when you try to do it for t^2. come sup with error.
What is the error, and the line(s) of code that you are using?
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.
y=diff(t,t);
plot(y,t)
returning an error
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)
yeah it works, but when u integrate that technique into a different equation, it triggers an error.
its ok, i fixed it. thanks for your help sir.
You are welcome.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息
另请参阅
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
