我有离散形式的以下函数(这意味着它们是数组):
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
点和[{1}}点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
但它不起作用。实际上我不知道我所做的一切是否正确所以一些反馈将非常感激!
答案 0 :(得分: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
的正确调用是:
[T,V] = ode45(last_fun,tspan,x0);
前提是tspan
和x0
是向量,tspan
按升序排序。