(* Mathematica中盡量以分數表示,避免精位數發生問題 *)
f=5/1000;
g[t_]:=2UnitStep[t]-4UnitStep[t-f]+4UnitStep[t-2f]-
4UnitStep[t-3f]+4UnitStep[t-4f]-4UnitStep[t-5f]+
4UnitStep[t-6f]
vv[t_]=v[t]/.
DSolve[{v'[t]+v[t]/(50*10^-9*7000)==(g[t])/(50*10^-9*7000),v[0]==0},v[t],t];
Plot[Evaluate@vv[t],{t,0,6f},PlotRange->All,PlotPoints->2000]
(* 一定要加Simplify,否則Mathematica無法將函數轉成piecewise,Plot函數取點時會導致失真 *)
Plot[Evaluate@Simplify@vv[t],{t,0,6f},PlotRange->All,PlotPoints->2000]
Mathematica 教學 Dsolve及UnitStep繪圖
由 戴忠淵 於 2012年10月23日星期二
下午11:21 發表
![作者 bjiyxo (若自礌) 看板 Mathematica 標題 [問題] Dsolve出了問題不太理解 時間 Tue Oct 23 17:47:59 2012 ─────────────────────────────────────── f = 0.005 g[t_] := 2 UnitStep[t] - 4 UnitStep[t - f] + 4 UnitStep[t - 2 f] - 4 UnitStep[t - 3 f] + 4 UnitStep[t - 4 f] - 4 UnitStep[t - 5 f] + 4 UnitStep[t - 6 f] sol = DSolve[{v'[t] + v[t]/(50*10^-9*7000) == (g[t])/(50*10^-9*7000), v[0] == 0}, v, t] 可是當我跑完上面那一行時,他就會出現Reduce::ratnz: Reduce was unable to solve \ the system with inexact coefficients. The answer was obtained by solving a corresponding exact system and numericizing the result. >> 我要做的事情大概就是個RC電路用方波時的圖形,可是當我打出v[0]=0的時候他就會跑出 上面那一行,請問我應該怎麼辦?](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjM1BePhUtPj1H6sj6qgdX9OPrMTVFrlrLd2_byv75MHzhJGIXeHWVoQJPaPb9kQOpPxdy3mo0adWeeze-sP6R0EMif-y5iRwws9Uy44NI0OkaaQOXjUpFBHd6E3AoeVttsl7akLqV3myk/s400/%E8%9E%A2%E5%B9%95%E5%BF%AB%E7%85%A7+2012-10-23+%E4%B8%8B%E5%8D%8811.27.14.png)


讀者回應 ( 0 意見 )
訂閱發佈留言 (Atom)
發佈留言
Please leave your name and tell me what you thought about this site. Comments, suggestions and views are welcomed.
如果這篇文章對你有幫助,那請留個訊息給我~