2014-10-16 51 views
0

我在离散形式以下功能(这意味着它们是数组):乘以2个功能句柄并施加ODE45到结果

p1_1 of dim(200x1) 
p1_2 of dim(200x1) 
p1_3 of dim(200x1) 
p2_1 of dim(200x1) 
p2_2 of dim(200x1) 
p2_3 of dim(200x1) 

p1_1, p1_2, p1_3已被评估的x1 = 0:(10/199):10和一个点的功能功能p2_1, p2_2, p2_3在点x2 = 0:(10/199):10

因为我有函数值,并在功能评价的,我也能做到以下几点:

fun1_of_p1 = @(xq1) interp1(x1,p1_1,xq1); 
fun1_of_p2 = @(xq1) interp1(x1,p1_2,xq1); 
fun1_of_p3 = @(xq1) interp1(x1,p1_3,xq1); 

fun2_of_p1 = @(xq2) interp1(x2,p2_1,xq2); 
fun2_of_p2 = @(xq2) interp1(x2,p2_2,xq2); 
fun2_of_p3 = @(xq2) interp1(x2,p2_3,xq2); 

然后我需要能够做以下:

new_fun1 = @(xq1,xq2) fun1_of_p1.*fun2_of_p1; 
new_fun2 = @(xq1,xq2) fun1_of_p1.*fun2_of_p2; 
new_fun3 = @(xq1,xq2) fun1_of_p1.*fun2_of_p3; 
new_fun4 = @(xq1,xq2) fun1_of_p2.*fun2_of_p1; 
new_fun5 = @(xq1,xq2) fun1_of_p2.*fun2_of_p2; 
new_fun6 = @(xq1,xq2) fun1_of_p2.*fun2_of_p3; 
new_fun7 = @(xq1,xq2) fun1_of_p3.*fun2_of_p1; 
new_fun8 = @(xq1,xq2) fun1_of_p3.*fun2_of_p2; 
new_fun9 = @(xq1,xq2) fun1_of_p3.*fun2_of_p3; 

最后

last_fun = @(xq1,xq2) gamma1*new_fun1 + gamma2*new_fun2 +... 
gamma3*new_fun3 + gamma4*new_fun4 + gamma5*new_fun4 +... 
gamma6*new_fun6 + gamma7*new_fun7 + gamma8*new_fun8 +... 
gamma9*new_fun9; 

gamma-值只是常数(实数值常量)。我已经定义last_fun后,我需要申请ode45它,但我不知道该怎么做,我想:

([T,V] = ode45(@(xq1,xq2)last_fun(xq1,xq2),tspan,x0) 

但它不工作。其实我不知道我所做的一切是否正确,所以一些反馈将非常感谢!

回答

2

将函数的句柄看作标记(或地址,ID等),以标识该函数等。这些标签是数字(计算机中的所有内容都是数字),但它们并不代表函数可能采用的值。要获取这些值,您必须提供函数的ID 函数的参数。

现在,当你说功能复用你的意思是返回功能,而不是功能标签的乘法功能。这导致了正确的定义:

new_fun1 = @(xq1,xq2) fun1_of_p1(xq1).*fun2_of_p1(xq2); 
new_fun2 = @(xq1,xq2) fun1_of_p1(xq1).*fun2_of_p2(xq2); 
new_fun3 = @(xq1,xq2) fun1_of_p1(xq1).*fun2_of_p3(xq2); 
new_fun4 = @(xq1,xq2) fun1_of_p2(xq1).*fun2_of_p1(xq2); 
new_fun5 = @(xq1,xq2) fun1_of_p2(xq1).*fun2_of_p2(xq2); 
new_fun6 = @(xq1,xq2) fun1_of_p2(xq1).*fun2_of_p3(xq2); 
new_fun7 = @(xq1,xq2) fun1_of_p3(xq1).*fun2_of_p1(xq2); 
new_fun8 = @(xq1,xq2) fun1_of_p3(xq1).*fun2_of_p2(xq2); 
new_fun9 = @(xq1,xq2) fun1_of_p3(xq1).*fun2_of_p3(xq2); 

还请更正以同样的方式在last_fun表达:

last_fun = @(xq1,xq2) ... 
    gamma1*new_fun1(xq1,xq2) ... 
    + gamma2*new_fun2(xq1,xq2) ... 
    + gamma3*new_fun3(xq1,xq2) ... 
    + gamma4*new_fun4(xq1,xq2) ... 
    + gamma5*new_fun4(xq1,xq2) ... 
    + gamma6*new_fun6(xq1,xq2) ... 
    + gamma7*new_fun7(xq1,xq2) ... 
    + gamma8*new_fun8(xq1,xq2) ... 
    + gamma9*new_fun9(xq1,xq2); 

ode45正确的调用是:只要tspan

[T,V] = ode45(last_fun,tspan,x0); 

x0是向量,tspan是向上排序的。

+0

谢谢你的答案!我会立即纠正这些功能!顺便说一句,令人惊讶的是你解释一个函数的句柄是什么!我现在可以申请'ode45'吗?如何才能制定出应用'ode45'的正确方法? – 2014-10-16 11:55:24

+1

只要'tspan'和'x0'具有相同的大小和向量,正确的方法是'[T,V] = ode45(last_fun,tspan,x0)'。 – 2014-10-16 12:00:57

+0

再次感谢!我会检查你的建议! :) – 2014-10-16 12:02:19