我有以下离散形式的函数(这意味着它们是数组):
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)
但这是行不通的。其实我不知道我所做的一切是否正确,所以一些反馈将不胜感激!
可以将功能的句柄视为可以识别该功能的标签(或地址,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
将是:
[T,V] = ode45(last_fun,tspan,x0);
前提是tspan
和x0
是向量,并且tspan
按升序排序。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句