2014-09-24 76 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]]. 

然后,你可以使用这个函数与我不同的我从你的范围来创建你想要的图。