2014-09-24 30 views
1

我無法通過使用Do循環在單獨的圖上繪製多個函數。我已經想出瞭如何爲一個合適的功能做到這一點,但現在我必須爲9個更適合的功能做到這一點。如何在do循環中繪製多個函數

m = 10; 
t0IGList = {0.01, 0.01, 0.012, 0.015, 0.018, 0.022, 0.028, 0.035, 
0.042, 0.05}; 

SubDataFit = 
NonlinearModelFit[SubDataList[[1]], 
A/(1 + (2 (t - t0)/\[Sigma])^2) + 
B0, {{A, 0.7}, {t0, t0IGList[[1]]}, {\[Sigma], 0.006}, {B0, 7.0}}, 
t]; 

SubFitPlot = 
Plot[SubDataFit[t], {t, 0, 0.07}, ImageSize -> 500, 
FrameLabel -> {"Time (s)", "Voltage (V)"}, PlotStyle -> Red, 
PlotRange -> {7, 7.8}]; 

Do[{ 
    SubDataFit[[i]] = 
    NonlinearModelFit[SubDataList[[i]], 
    A/(1 + (2 (t - t0)/\[Sigma])^2) + 
    B0, {{A, 0.7}, {t0, t0IGList[[i]]}, {\[Sigma], 0.006}, {B0, 
    7.0}}, t]; 
    SubFitPlot = 
    Plot[SubDataFit[t], {t, 0, 0.07}, ImageSize -> 500, 
    FrameLabel -> {"Time (s)", "Voltage (V)"}, PlotStyle -> Red]; 
    Print["B = ", i, "Volts"]; 
    Print[SubDataPlot];}, {i, 1, m}]; 

回答

0

你說你想繪製「單獨圖上的多個函數」,這似乎意味着你想要10個獨立的圖。如果那是正確的。如果是這樣,你可以分離出你想要的兩部分:在循環中生成擬合併將它們收集到列表中,然後繪製擬合的函數。你可以使你的繪圖功能像你想的那樣複雜。簡單的例子:

flst = {x, x^2, x^3, Log[x]} 
Plot[#, {x, 0.01, 2}] & /@ flst 

一旦你有地塊,你可以做任何他們想要的這個列表(例如,做一個GraphicsGrid,或Export他們,等等)

0

嘗試使用模塊。創建一個功能

plot[i_]:=Module[{local variables for module}, 
    Any actions you want: fits, calculations etc. Separate them with ";"; 
    Plot[i-th function]]. 

然後,你可以使用這個函數與我不同的我從你的範圍來創建你想要的圖。