简体   繁体   English

matlab连接的矩阵尺寸不一致

[英]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)

Source of Error 错误来源

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. 这会导致尺寸不匹配,从而导致错误。

Solutions 解决方案

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.

相关问题 使用CAT的matlab错误,所连接矩阵的维数不一致 - matlab error using CAT, Dimensions of matrices being concatenated are not consistent bsxfun:所连接矩阵的维数不一致 - bsxfun: Dimensions of matrices being concatenated are not consistent 我如何处理“使用vertcat的错误连接矩阵的尺寸在Matlab中不一致”? - How do i handle “Error using vertcat Dimensions of matrices being concatenated are not consistent” in Matlab? 如何解决:使用horzcat时发生错误所连接矩阵的维数不一致 - How to solve: Error using horzcat Dimensions of matrices being concatenated are not consistent 使用带有字符的数组时,要级联的矩阵的维数不一致 - Dimensions of matrices being concatenated are not consistent using array with characters 使用垂直时发生错误:串联的矩阵尺寸不一致 - Error using vertical: Dimensions of matrices being concatenated are not consistent Matlab代码崩溃并给出错误:所连接矩阵的维数不一致 - Matlab code crashes and gives error: Dimension of matrices being concatenated are not consistent 在MATLAB中调试错误“被连接的数组的维度不一致” - Debugging the error "Dimensions of arrays being concatenated are not consistent" in MATLAB 使用 horzcat 时出错 连接的 arrays 的维度不一致。 Matlab - Error using horzcat Dimensions of arrays being concatenated are not consistent. Matlab 在1x6802 double和6802x1 double数据矩阵中,级联矩阵的尺寸不一致 - Dimensions of matrices being concatenated are not consistent in 1x6802 double and 6802x1 double data matrix
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM