2017-09-27 67 views

回答

1

ode允许额外函数的参数列表:

它可能发生模拟器˚F需要额外的参数。在这个 的情况下,我们可以使用以下功能。 f参数也可以是一个 list lst = list(f,u1,u2,... un)其中f是一个带有 语法的Scilab函数:ydot = f(t,y,u1,u2,..., un)和u1,u2,...,un是额外的 自动传递给模拟器simuf的参数。

额外的参数是t的函数

function y = f(t,y,h) 
// define y here depending on t and h(t),eg y = t + h(t) 
endfunction 

function y = h(t) 
// define here h(t), eg y = t 
endfunction 

// define y0,t0 and t 
y = ode(y0, t0, t, list(f,h)) // this will pass the h function as a parameter 

Extra是我们要提取的对应项的向量。

由于ode只计算解决方案yt。当ode执行计算并获得Hi < h < Hj时,想法是寻找Ti < t < Tj

这是相当难看,但完全的工作原理:

function y = h(t,T,H) 
    res = abs(t - T)   // looking for nearest value of t in T 
    minres = min(res)   // getting the smallest distance 
    lower = find(res==minres) // getting the index : T(lower) 
    res(res==minres)=%inf  // looking for 2nd nearest value of t in T: nearest is set to inf 
    minres = min(res)   // getting the smallest distance 
    upper = find(minres==res) // getting the index: T(upper) 
    // Now t is between T(lower) (nearest) and T(upper) (farest) (! T(lower) may be > T(upper)) 
    y = ((T(upper)-t)*H(lower)+(t-T(lower))*H(upper))/(T(upper)-T(lower)) // computing h such as the barycenter with same distance to H(lower) and H(upper) 
endfunction 

function ydot=f(t, y,h,T,H) 
    hi = h(t,T,H)  // if Ti< t < Tj; Hi<h(t,T,H)<Hj 
    disp([t,hi])  // with H = T, hi = t 
    ydot=y^2-y*sin(t)+cos(t) - hi // example of were to use hi 
endfunction 

// use base example of `ode` 
y0=0; 
t0=0; 
t=0:0.1:%pi; 
H = t // simple example 
y = ode(y0,t0,t,list(f,h,t,H)); 
plot(t,y) 
+0

我读过在SciLab的帮助并不能设法使其工作,但你的例子很容易!这解决了我的问题的50%,因为现在我可以使用它解决直接问题,但我仍然需要解决相反的问题,为此我可能需要另一个功能,我不知道SciLab是否有这个功能。有没有办法在每次SciLab自动选择一个接一个之后传递一个参数作为向量?例如: 't = [1 2 3]; h = [7 8 9]; sol = ode(yo,to,t,list(f,h))'因此,在这种情况下,t = 1时使用h = 7,t = 2时使用h = 8等等。 – Alexandre

+0

改进我的答案。写在我的手机上,所以这只是一个猜测。请告诉我,如果这个工程! – PTRK

+0

不幸的是,它没有。我在函数y = f(t,h,T)中打印了t的值......这些值完全不同于向量t中传递的值,好奇地是它从不出现t的值,因此'h find(t == T))'从来没有找到一个值。不过,我可以做出错误的事情。我发现使它工作的唯一方法是实现Rung-Kutta,所以我更好地控制了传递的参数。但我真的很感谢你的帮助。非常感谢,我的朋友! – Alexandre