[英]matlab Dimensions of matrices being concatenated are not consistent
here is my code: 这是我的代码:
C=@(k) [k,k,2.*k;3,2.*k,5;1,k,k];
AV=@(k,t) [3*t, 6, 9]*C(k)*[3*t ;6 ;9];
avaint=@(k,a,b) quadgk(@(k) AV(k,t),a,b);
AVAR=@(t) avaint(t,0,87600);
Is shows: 显示:
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
when I want to print AVAR(3)
当我想打印AVAR(3)
The quadgk
function passes a vector of integration points to the function handle given to it. quadgk
函数将积分点的矢量传递给给它的函数句柄。 From the documentation : 从文档中 :
The function y = fun(x) should accept a vector argument x and return a vector result y, where y is the integrand evaluated at each element of x. 函数y = fun(x)应该接受向量参数x并返回向量结果y,其中y是在x的每个元素处求值的被积数。
This creates the dimension mismatch causing the error. 这会导致尺寸不匹配,从而导致错误。
To get around this implementation, you can perform the numerical integration using the integral
function with the ( 'ArrayValued'
, true
) option pair: 为了解决这个问题,您可以使用带有( 'ArrayValued'
, true
)选项对的integral
函数执行数值积分:
avaint = @(t,a,b) integral(@(k) AV(k,t),a,b,'ArrayValued',true);
Or, you can use arrayfun
within AV
to abide by the requirement of quadgk
: 或者,您可以在AV
使用arrayfun
来满足quadgk
的要求:
AV = @(k,t) arrayfun(@(k_el) [3*t, 6, 9]*(C(k_el)*[3*t ;6 ;9]),k);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.